From 626658074c8dd5c2288becd836103e2efdb9b741 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Thu, 17 Sep 2020 15:24:55 +0000 Subject: [PATCH] cmd: Recycle input node before it executes. Avoids memory leak and infinite loop on the most recent node if a Host_Error occurs during execution. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12933 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index d0ef7750..29eef47b 100644 --- a/cmd.c +++ b/cmd.c @@ -448,7 +448,10 @@ void Cbuf_Execute (cmd_buf_t *cbuf) * can insert data at the beginning of the text buffer */ current = List_Container(*cbuf->start.next, cmd_input_t, list); - + + // Recycle memory so using WASD doesn't cause a malloc and free + List_Move_Tail(¤t->list, &cbuf->free); + /* * Assume we're rolling with the current command-line and * always set this false because alias expansion or cbuf insertion @@ -473,9 +476,6 @@ void Cbuf_Execute (cmd_buf_t *cbuf) Cmd_ExecuteString (current->source, current->text, src_local, false); } - // Recycle memory so using WASD doesn't cause a malloc and free - List_Move_Tail(¤t->list, &cbuf->free); - current = NULL; if (cbuf->wait) -- 2.39.2