Skip to content

Commit c897c69

Browse files
committed
Avoid Coverity warning about unfree()d git_exec_path()
Technically, it is correct that git_exec_path() returns a possibly malloc()ed string. Practically, it is *sometimes* not malloc()ed. So let's just use a static variable to make it a singleton. That'll shut Coverity up, hopefully. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 58e7864 commit c897c69

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

exec_cmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void git_set_argv_exec_path(const char *exec_path)
6565
const char *git_exec_path(void)
6666
{
6767
const char *env;
68+
static char *system_exec_path;
6869

6970
if (argv_exec_path)
7071
return argv_exec_path;
@@ -74,7 +75,9 @@ const char *git_exec_path(void)
7475
return env;
7576
}
7677

77-
return system_path(GIT_EXEC_PATH);
78+
if (!system_exec_path)
79+
system_exec_path = system_path(GIT_EXEC_PATH);
80+
return system_exec_path;
7881
}
7982

8083
static void add_path(struct strbuf *out, const char *path)

0 commit comments

Comments
 (0)