From 6934b72a4521d8c4aeb9edab8cfb87897007b114 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 4 Nov 2009 14:00:03 -0500 Subject: [PATCH] Simplify debug_fn() We don't need to be allocating an output string here. This was also causing a runtime bug when the output string contained characters that would be interpreted by fprintf as specifiers. --- server/util/debug.c | 13 ++----------- 1 files changed, 2 insertions(+), 11 deletions(-) diff --git a/server/util/debug.c b/server/util/debug.c index 862367c..f41af4b 100644 --- a/server/util/debug.c +++ b/server/util/debug.c @@ -56,23 +56,14 @@ errno_t set_debug_file_from_fd(const int fd) void debug_fn(const char *format, ...) { va_list ap; - char *s = NULL; int ret; va_start(ap, format); - ret = vasprintf(&s, format, ap); - if (ret < 0) { - /* ENOMEM */ - return; - } + vfprintf(debug_file ? debug_file : stderr, format, ap); + fflush(debug_file ? debug_file : stderr); va_end(ap); - - /*write(state.fd, s, strlen(s));*/ - fprintf(debug_file ? debug_file : stderr, s); - fflush(debug_file ? debug_file : stderr); - free(s); } void ldb_debug_messages(void *context, enum ldb_debug_level level, -- 1.6.2.5