[PATCH 2/3] setup_path(): Free temporary buffer
- From
Carlos Martín Nieto <cmn@elego.de>
- Date
- Mar 14, 2011, 19:18 UTC
- Message-ID
- <1300130318-11279-3-git-send-email-cmn@elego.de>
- In-Reply-To
- <1300130318-11279-1-git-send-email-cmn@elego.de>
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@elego.de> --- 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