[util] Add a function to reverse delete cbuf stacks

I'm not 100% sure this is the best fix for the issue, but the way the
cbuf interpreter stack works (especially in the console code) meant that
the stack was built in the order opposite to how it could be safely
deleted with the existing function. Yeah, more leaks :P
This commit is contained in:
Bill Currie 2023-03-05 17:23:11 +09:00
parent 340127fff2
commit b84bf16cab
3 changed files with 13 additions and 1 deletions

View File

@ -92,6 +92,7 @@ cbuf_t * Cbuf_New (cbuf_interpreter_t *interp);
void Cbuf_Delete (cbuf_t *cbuf);
void Cbuf_DeleteStack (cbuf_t *stack);
void Cbuf_DeleteStackReverse (cbuf_t *stack);
void Cbuf_Reset (cbuf_t *cbuf);
cbuf_t *Cbuf_PushStack (cbuf_interpreter_t *interp);
void Cbuf_AddText (cbuf_t *cbuf, const char *text);

View File

@ -123,6 +123,17 @@ Cbuf_DeleteStack (cbuf_t *stack)
}
}
VISIBLE void
Cbuf_DeleteStackReverse (cbuf_t *stack)
{
cbuf_t *next;
for (; stack; stack = next) {
next = stack->up;
Cbuf_Delete (stack);
}
}
void
Cbuf_Reset (cbuf_t *cbuf)
{

View File

@ -486,7 +486,7 @@ main (int argc, char **argv)
free (thread_data.a[i]);
}
DARRAY_CLEAR (&thread_data);
Cbuf_Delete (qwaq_cbuf);
Cbuf_DeleteStackReverse (qwaq_cbuf);
Sys_Shutdown ();
return ret;
}