]> git.ipfire.org Git - thirdparty/git.git/commitdiff
clone: fix a memory leak of the "git_dir" variable
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 22 Oct 2021 08:55:42 +0000 (10:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 23 Oct 2021 17:45:25 +0000 (10:45 -0700)
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>
builtin/clone.c

index 559acf9e03685e5b7f1fa4936685cc6570d716fc..fb377b27657c4048a04c85ddb82e15a950db5a7d 100644 (file)
@@ -1040,8 +1040,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
                INIT_DB_QUIET);
 
-       if (real_git_dir)
+       if (real_git_dir) {
+               free((char *)git_dir);
                git_dir = real_git_dir;
+       }
 
        /*
         * additional config can be injected with -c, make sure it's included