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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 22, 2021 at 10:55 UTC 27ff1fbc5dd5ca5f03a65bfc734c913703e8cdf7
1 file changed +3 -1
builtin/clone.c
+3 -1
@@ -1040,8 +1040,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1040 init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
1041 INIT_DB_QUIET);
1042
1043 - if (real_git_dir)
1043 + if (real_git_dir) {
1044 + free((char *)git_dir);
1045 git_dir = real_git_dir;
1046 + }
1047
1048 /*
1049 * additional config can be injected with -c, make sure it's included