]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: fix leaking repository format
authorPatrick Steinhardt <ps@pks.im>
Mon, 6 Nov 2023 10:46:05 +0000 (11:46 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Nov 2023 23:51:41 +0000 (08:51 +0900)
While populating the `repository_format` structure may cause us to
allocate memory, we do not call `clear_repository_format()` in some
places and thus potentially leak memory. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c

diff --git a/setup.c b/setup.c
index b9474b163a0f5396d3729cea17c12e48cc733a8f..fc592dc6dd5bf3f2ac7ac01ca0d72b7ce0129e77 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -722,6 +722,7 @@ int upgrade_repository_format(int target_version)
        ret = 1;
 
 out:
+       clear_repository_format(&repo_fmt);
        strbuf_release(&repo_version);
        strbuf_release(&err);
        return ret;
@@ -2199,6 +2200,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
                               git_dir, len && git_dir[len-1] != '/' ? "/" : "");
        }
 
+       clear_repository_format(&repo_fmt);
        free(original_git_dir);
        return 0;
 }