diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-11-08 07:04:41 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-11-08 07:04:41 +0100 |
commit | c732f7430da8d4dedccd05540eae3dc7421dcdc6 (patch) | |
tree | 2a965ad665788e71bf9143d0f844f419b3f32a7e | |
parent | Prepare for -rc1 (diff) | |
parent | setup: fix leaking repository format (diff) | |
download | git-c732f7430da8d4dedccd05540eae3dc7421dcdc6.tar.xz git-c732f7430da8d4dedccd05540eae3dc7421dcdc6.zip |
Merge branch 'ps/leakfixes'
Leakfix.
* ps/leakfixes:
setup: fix leaking repository format
setup: refactor `upgrade_repository_format()` to have common exit
shallow: fix memory leak when registering shallow roots
test-bloom: stop setting up Git directory twice
-rw-r--r-- | setup.c | 33 | ||||
-rw-r--r-- | shallow.c | 4 | ||||
-rw-r--r-- | t/helper/test-bloom.c | 1 | ||||
-rwxr-xr-x | t/t5311-pack-bitmaps-shallow.sh | 2 | ||||
-rwxr-xr-x | t/t5530-upload-pack-error.sh | 1 |
5 files changed, 28 insertions, 13 deletions
@@ -693,29 +693,39 @@ int upgrade_repository_format(int target_version) struct strbuf err = STRBUF_INIT; struct strbuf repo_version = STRBUF_INIT; struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; + int ret; strbuf_git_common_path(&sb, the_repository, "config"); read_repository_format(&repo_fmt, sb.buf); strbuf_release(&sb); - if (repo_fmt.version >= target_version) - return 0; + if (repo_fmt.version >= target_version) { + ret = 0; + goto out; + } if (verify_repository_format(&repo_fmt, &err) < 0) { - error("cannot upgrade repository format from %d to %d: %s", - repo_fmt.version, target_version, err.buf); - strbuf_release(&err); - return -1; + ret = error("cannot upgrade repository format from %d to %d: %s", + repo_fmt.version, target_version, err.buf); + goto out; + } + if (!repo_fmt.version && repo_fmt.unknown_extensions.nr) { + ret = error("cannot upgrade repository format: " + "unknown extension %s", + repo_fmt.unknown_extensions.items[0].string); + goto out; } - if (!repo_fmt.version && repo_fmt.unknown_extensions.nr) - return error("cannot upgrade repository format: " - "unknown extension %s", - repo_fmt.unknown_extensions.items[0].string); strbuf_addf(&repo_version, "%d", target_version); git_config_set("core.repositoryformatversion", repo_version.buf); + + ret = 1; + +out: + clear_repository_format(&repo_fmt); strbuf_release(&repo_version); - return 1; + strbuf_release(&err); + return ret; } static void init_repository_format(struct repository_format *format) @@ -2190,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; } @@ -38,8 +38,10 @@ int register_shallow(struct repository *r, const struct object_id *oid) oidcpy(&graft->oid, oid); graft->nr_parent = -1; - if (commit && commit->object.parsed) + if (commit && commit->object.parsed) { + free_commit_list(commit->parents); commit->parents = NULL; + } return register_commit_graft(r, graft, 0); } diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index aabe31d724..1281e66876 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -40,7 +40,6 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid) { struct commit *c; struct bloom_filter *filter; - setup_git_directory(); c = lookup_commit(the_repository, commit_oid); filter = get_or_compute_bloom_filter(the_repository, c, 1, &settings, diff --git a/t/t5311-pack-bitmaps-shallow.sh b/t/t5311-pack-bitmaps-shallow.sh index 9dae60f73e..4fe71fe8cd 100755 --- a/t/t5311-pack-bitmaps-shallow.sh +++ b/t/t5311-pack-bitmaps-shallow.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='check bitmap operation with shallow repositories' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # We want to create a situation where the shallow, grafted diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh index 558eedf25a..7172780d55 100755 --- a/t/t5530-upload-pack-error.sh +++ b/t/t5530-upload-pack-error.sh @@ -2,6 +2,7 @@ test_description='errors in upload-pack' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) |