From: cloudwalk Date: Thu, 17 Sep 2020 15:24:55 +0000 (+0000) Subject: cmd: Recycle input node before it executes. Avoids memory leak and infinite loop... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=626658074c8dd5c2288becd836103e2efdb9b741;p=xonotic%2Fdarkplaces.git 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 --- 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)