From d5b0a51b6e103b961621b839043661d12e88ff78 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 27 Dec 2023 16:03:05 +0900 Subject: [PATCH] [dstring] Use va_copy correctly Every use of va_copy needs a corresponding call to va_end. I had somehow missed that when getting _dvsprintf to work properly. This seems to plug a memory leak (certainly doesn't make things worse). --- libs/util/dstring.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/util/dstring.c b/libs/util/dstring.c index dc478b8c2..c2b6ae6f7 100644 --- a/libs/util/dstring.c +++ b/libs/util/dstring.c @@ -301,12 +301,12 @@ dstring_clearstr (dstring_t *dstr) } static __attribute__((format(PRINTF, 3, 0))) char * -_dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args) +_dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list srcargs) { int size; - va_list tmp_args; - va_copy (tmp_args, args); + va_list args; + va_copy (args, srcargs); if (!dstr->truesize) dstring_clearstr (dstr); // Make it a string @@ -315,15 +315,18 @@ _dvsprintf (dstring_t *dstr, int offs, const char *fmt, va_list args) args)) == -1) { dstr->size = (dstr->truesize & ~1023) + 1024; dstring_adjust (dstr); - va_copy (args, tmp_args); + va_end (args); + va_copy (args, srcargs); } dstr->size = size + offs + 2; // "Proper" implementations return the required size if (dstr->size > dstr->truesize) { dstring_adjust (dstr); - va_copy (args, tmp_args); + va_end (args); + va_copy (args, srcargs); vsnprintf (dstr->str + offs, dstr->truesize - offs - 1, fmt, args); } + va_end (args); dstr->size = size + offs + 1; dstr->str[dstr->size - 1] = 0; return dstr->str;