[PATCH 2/3] setup_path(): Free temporary buffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make sure the pointer git_exec_path() returns is in the heap and free
it after it's no longer needed.

Signed-off-by: Carlos MartÃn Nieto <cmn@xxxxxxxx>
---
 exec_cmd.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index 38545e8..c16c3d4 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -73,11 +73,11 @@ const char *git_exec_path(void)
 	const char *env;
 
 	if (argv_exec_path)
-		return argv_exec_path;
+		return xstrdup(argv_exec_path);
 
 	env = getenv(EXEC_PATH_ENVIRONMENT);
 	if (env && *env) {
-		return env;
+		return xstrdup(env);
 	}
 
 	return system_path(GIT_EXEC_PATH);
@@ -99,10 +99,13 @@ void setup_path(void)
 {
 	const char *old_path = getenv("PATH");
 	struct strbuf new_path = STRBUF_INIT;
+	char *exec_path = (char *) git_exec_path();
 
-	add_path(&new_path, git_exec_path());
+	add_path(&new_path, exec_path);
 	add_path(&new_path, argv0_path);
 
+	free(exec_path);
+
 	if (old_path)
 		strbuf_addstr(&new_path, old_path);
 	else
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]