Skip to content

Commit

Permalink
Merge branch 'ps/leakfixes'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Nov 8, 2023
2 parents 98009af + 9972cd6 commit c732f74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
33 changes: 22 additions & 11 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion shallow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion t/helper/test-bloom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions t/t5311-pack-bitmaps-shallow.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions t/t5530-upload-pack-error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

test_description='errors in upload-pack'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

D=$(pwd)
Expand Down

0 comments on commit c732f74

Please sign in to comment.