From: Ævar Arnfjörð Bjarmason Date: Fri, 22 Oct 2021 08:55:42 +0000 (+0200) Subject: clone: fix a memory leak of the "git_dir" variable X-Git-Tag: v2.34.0-rc0~15^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=27ff1fbc5dd5ca5f03a65bfc734c913703e8cdf7;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/clone.c b/builtin/clone.c index 559acf9e03..fb377b2765 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -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