summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-30 11:13:51 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-30 20:23:06 +0200
commit55e563a90cabacd144b529b8bab7c4bb1cecbc49 (patch)
treed689eeb99935a8ff6774b87dcaaa52eca358cac8
parentline-log: fix several memory leaks (diff)
downloadgit-55e563a90cabacd144b529b8bab7c4bb1cecbc49.tar.xz
git-55e563a90cabacd144b529b8bab7c4bb1cecbc49.zip
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>
-rw-r--r--pack-bitmap-write.c8
-rw-r--r--pack-bitmap.c4
-rw-r--r--pseudo-merge.c19
-rw-r--r--pseudo-merge.h2
4 files changed, 31 insertions, 2 deletions
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 4dc0fe8e40..6413dd1731 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -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];
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 9d9b8c4bfb..32b222a7af 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1390,8 +1390,8 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
}
base = bitmap_new();
- if (!cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap))
- bitmap_free(roots_bitmap);
+ cascade_pseudo_merges_1(bitmap_git, base, roots_bitmap);
+ bitmap_free(roots_bitmap);
}
/*
diff --git a/pseudo-merge.c b/pseudo-merge.c
index 10ebd9a4e9..28782a31c6 100644
--- a/pseudo-merge.c
+++ b/pseudo-merge.c
@@ -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)
diff --git a/pseudo-merge.h b/pseudo-merge.h
index 4b5febaa63..29df8a32ec 100644
--- a/pseudo-merge.h
+++ b/pseudo-merge.h
@@ -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;