From b84bf16cabd1d46a5725ad41ab80803569cfb706 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 5 Mar 2023 17:23:11 +0900 Subject: [PATCH] [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 --- include/QF/cbuf.h | 1 + libs/util/cbuf.c | 11 +++++++++++ ruamoko/qwaq/builtins/main.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/QF/cbuf.h b/include/QF/cbuf.h index 29a89588e..5566ee7aa 100644 --- a/include/QF/cbuf.h +++ b/include/QF/cbuf.h @@ -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); diff --git a/libs/util/cbuf.c b/libs/util/cbuf.c index 2249499e7..36765daf2 100644 --- a/libs/util/cbuf.c +++ b/libs/util/cbuf.c @@ -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) { diff --git a/ruamoko/qwaq/builtins/main.c b/ruamoko/qwaq/builtins/main.c index a0c291d79..8b9ff541c 100644 --- a/ruamoko/qwaq/builtins/main.c +++ b/ruamoko/qwaq/builtins/main.c @@ -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; }