Skip to content

Commit 27ff1fb

Browse files
avargitster
authored andcommitted
clone: fix a memory leak of the "git_dir" variable
At this point in cmd_clone the "git_dir" is always either an xstrdup()'d string, or something we got from mkpathdup(). Let's free() it before we clobber it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b202e51 commit 27ff1fb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10401040
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
10411041
INIT_DB_QUIET);
10421042

1043-
if (real_git_dir)
1043+
if (real_git_dir) {
1044+
free((char *)git_dir);
10441045
git_dir = real_git_dir;
1046+
}
10451047

10461048
/*
10471049
* additional config can be injected with -c, make sure it's included

0 commit comments

Comments
 (0)