mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-24 20:51:35 +00:00
[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).
This commit is contained in:
parent
75171743a4
commit
d5b0a51b6e
1 changed files with 8 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue