From 1b40844aa3b7a94fd84533ed6ef78a5c5cbac5f1 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Fri, 9 Oct 2020 23:51:49 -0400
Subject: Fix memory leak in run_hook()

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/hooks.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/hooks.c b/src/hooks.c
index 8fda0da..b4933af 100644
--- a/src/hooks.c
+++ b/src/hooks.c
@@ -41,15 +41,15 @@
 
 int run_hook(const char *name)
 {
-	char *hook_cmd = NULL, *mesg;
+	char *hook_path = NULL, *hook_cmd = NULL, *mesg;
 	char const *arg[2];
 	int pid, ret = -127;
 
-	asprintf(&hook_cmd, "%s/%s", path_hooks, name);
-	if (!io_file_exists(hook_cmd))
+	asprintf(&hook_path, "%s/%s", path_hooks, name);
+	if (!io_file_exists(hook_path))
 		goto cleanup;
 
-	asprintf(&hook_cmd, "%s <&- >&- 2>&-", hook_cmd);
+	asprintf(&hook_cmd, "%s <&- >&- 2>&-", hook_path);
 	arg[0] = hook_cmd;
 	arg[1] = NULL;
 
@@ -70,6 +70,7 @@ int run_hook(const char *name)
 	}
 
 cleanup:
+	mem_free(hook_path);
 	mem_free(hook_cmd);
 	return ret;
 }
-- 
cgit v1.2.3-70-g09d2