From 25dacf9256a1bef857b7454eab500fb20574ca18 Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Fri, 1 Nov 2019 15:29:59 +0000 Subject: [PATCH] wmbattery: fix a couple of potential memory-leaks. In `cmd_crit`, if there is an allocation failure, we return from the function immediately and leak any previously allocated memory. Go to the clean-up code at the end of the function instead. Signed-off-by: Jeremy Sowden --- wmbattery/wmbattery.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wmbattery/wmbattery.c b/wmbattery/wmbattery.c index f3c15c7..7c1a9d4 100644 --- a/wmbattery/wmbattery.c +++ b/wmbattery/wmbattery.c @@ -359,18 +359,20 @@ void cmd_crit(const char *cmd, int percentage, int time) return; tmp_b = replace_str(tmp_a, STR_SUB_MINUTES, min_str); if (!tmp_b) - return; + goto free_tmp_a; command = replace_str(tmp_b, STR_SUB_SECONDS, sec_str); if (!command) - return; + goto free_tmp_b; ret = system(command); if (ret == -1) error("unable to run command: %s", command); - free(tmp_a); - free(tmp_b); free(command); +free_tmp_b: + free(tmp_b); +free_tmp_a: + free(tmp_a); } /* Returns the display to run on (or NULL for default). */