From 128c155681ce12091dcb60b7b06b283090edace4 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Tue, 7 Feb 2012 22:46:45 -0800 Subject: [PATCH] Fix memory leak in commit 30d4f2b7 va_end() has to be called after each invocation of va_copy(). So when log messages are short, the copy was leaked. When log messages were long, the old ap would get lost. --- src/ctx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ctx.c b/src/ctx.c index 48e87ad..50f8300 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -256,7 +256,6 @@ void xmpp_log(const xmpp_ctx_t * const ctx, va_copy(copy, ap); ret = xmpp_vsnprintf(buf, 1023, fmt, ap); if (ret > 1023) { - va_copy(ap, copy); buf = (char *)xmpp_alloc(ctx, ret + 1); if (!buf) { buf = NULL; @@ -264,11 +263,13 @@ void xmpp_log(const xmpp_ctx_t * const ctx, return; } oldret = ret; - ret = xmpp_vsnprintf(buf, ret + 1, fmt, ap); + ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy); if (ret > oldret) { xmpp_error(ctx, "log", "Unexpected error"); return; } + } else { + va_end(copy); } if (ctx->log->handler)