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.
This commit is contained in:
committed by
Jack Moffitt
parent
311e09a99a
commit
128c155681
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user