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);
|
va_copy(copy, ap);
|
||||||
ret = xmpp_vsnprintf(buf, 1023, fmt, ap);
|
ret = xmpp_vsnprintf(buf, 1023, fmt, ap);
|
||||||
if (ret > 1023) {
|
if (ret > 1023) {
|
||||||
va_copy(ap, copy);
|
|
||||||
buf = (char *)xmpp_alloc(ctx, ret + 1);
|
buf = (char *)xmpp_alloc(ctx, ret + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
@@ -264,11 +263,13 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
oldret = ret;
|
oldret = ret;
|
||||||
ret = xmpp_vsnprintf(buf, ret + 1, fmt, ap);
|
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
||||||
if (ret > oldret) {
|
if (ret > oldret) {
|
||||||
xmpp_error(ctx, "log", "Unexpected error");
|
xmpp_error(ctx, "log", "Unexpected error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
va_end(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->log->handler)
|
if (ctx->log->handler)
|
||||||
|
|||||||
Reference in New Issue
Block a user