From b5d068b0ea4c8406e9f6eda44fd653d4fed0f326 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Thu, 13 Feb 2025 08:32:32 +0000 Subject: [PATCH] CodeQL MemoryMayNotBeFreed.ql rtrCmd.c CmdRoute() --- windows/windCmdAM.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/windows/windCmdAM.c b/windows/windCmdAM.c index c51ac9eb..e0120aef 100644 --- a/windows/windCmdAM.c +++ b/windows/windCmdAM.c @@ -1134,11 +1134,20 @@ windDoMacro(w, cmd, interactive) } } + cn = NULL; any = FALSE; ch = 0; HashStartSearch(&hs); while (TRUE) { + if (cn) + { + /* this loop uses 'continue' after 'cn' was assigned from malloc below, so + * this ensures it is freed up at the start of the next iteration. + */ + freeMagic(cn); + cn = NULL; + } h = HashNext(clienttable, &hs); if (h == NULL) break; cMacro = (macrodef *) HashGetValue(h); @@ -1186,7 +1195,6 @@ windDoMacro(w, cmd, interactive) TxPrintf("Macro '%s' %s \"%s\"\n", cn, (do_help) ? "" : "contains", cp); } - freeMagic(cn); any = TRUE; } if (!any)