pseudo-merge: fix various memory leaks

Fix various memory leaks hit by the pseudo-merge machinery. These leaks
are exposed by t5333, but plugging them does not yet make the whole test
suite pass.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-09-30 11:13:51 +02:00 committed by Junio C Hamano
parent 5ce08ed4fb
commit 55e563a90c
4 changed files with 31 additions and 2 deletions

View File

@ -64,6 +64,12 @@ static void free_pseudo_merge_commit_idx(struct pseudo_merge_commit_idx *idx)
free(idx);
}
static void pseudo_merge_group_release_cb(void *payload, const char *name UNUSED)
{
pseudo_merge_group_release(payload);
free(payload);
}
void bitmap_writer_free(struct bitmap_writer *writer)
{
uint32_t i;
@ -82,6 +88,8 @@ void bitmap_writer_free(struct bitmap_writer *writer)
kh_foreach_value(writer->pseudo_merge_commits, idx,
free_pseudo_merge_commit_idx(idx));
kh_destroy_oid_map(writer->pseudo_merge_commits);
string_list_clear_func(&writer->pseudo_merge_groups,
pseudo_merge_group_release_cb);
for (i = 0; i < writer->selected_nr; i++) {
struct bitmapped_commit *bc = &writer->selected[i];

View File

@ -1390,7 +1390,7 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
}
base = bitmap_new();
if (!cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap))
cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap);
bitmap_free(roots_bitmap);
}

View File

@ -97,6 +97,25 @@ static void pseudo_merge_group_init(struct pseudo_merge_group *group)
group->stable_size = DEFAULT_PSEUDO_MERGE_STABLE_SIZE;
}
void pseudo_merge_group_release(struct pseudo_merge_group *group)
{
struct hashmap_iter iter;
struct strmap_entry *e;
regfree(group->pattern);
free(group->pattern);
strmap_for_each_entry(&group->matches, &iter, e) {
struct pseudo_merge_matches *matches = e->value;
free(matches->stable);
free(matches->unstable);
free(matches);
}
strmap_clear(&group->matches, 0);
free(group->merges);
}
static int pseudo_merge_config(const char *var, const char *value,
const struct config_context *ctx,
void *cb_data)

View File

@ -51,6 +51,8 @@ struct pseudo_merge_group {
timestamp_t stable_threshold;
};
void pseudo_merge_group_release(struct pseudo_merge_group *group);
struct pseudo_merge_matches {
struct commit **stable;
struct commit **unstable;