From 0ac6827a9bf950688993b2b9924d411dea7108b7 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 16 May 2021 15:47:14 +0200 Subject: [PATCH] wmmenugen: Fix memory leaks when parsing menu in wmconfig format As reported by Coverity (CID #50181, #50182 and #50183) the strings allocated by parse_wmconfig_line were not freed after use. Signed-off-by: Christophe CURIS --- util/wmmenugen_parse_wmconfig.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/wmmenugen_parse_wmconfig.c b/util/wmmenugen_parse_wmconfig.c index 95425bc9..82ba0103 100644 --- a/util/wmmenugen_parse_wmconfig.c +++ b/util/wmmenugen_parse_wmconfig.c @@ -96,8 +96,10 @@ void parse_wmconfig(const char *file, cb_add_menu_entry *addWMMenuEntryCallback) parse_wmconfig_line(&label, &key, &value, p); - if (label && strlen(label) == 0) + if (label && strlen(label) == 0) { + wfree(label); continue; + } if (!lastlabel && label) lastlabel = wstrdup(label); @@ -110,6 +112,7 @@ void parse_wmconfig(const char *file, cb_add_menu_entry *addWMMenuEntryCallback) wfree(lastlabel); lastlabel = wstrdup(label); } + wfree(label); if (key && value) { if (strcmp(key, "name") == 0) @@ -124,10 +127,13 @@ void parse_wmconfig(const char *file, cb_add_menu_entry *addWMMenuEntryCallback) wmc->Flags |= F_TERMINAL; } + wfree(key); } fclose(fp); + wfree(lastlabel); + if (wmc_to_wm(&wmc, &wm)) { (*addWMMenuEntryCallback)(wm); init_wmconfig_storage(&wmc);