Skip to content

Commit d0ab663

Browse files
pks-tgitster
authored andcommitted
pseudo-merge: fix leaking strmap keys
When creating a new pseudo-merge group we collect a set of matchnig commits and put them into a string map. This strmap is initialized such that it does not allocate its keys, and instead we try to pass ownership of the keys to it via `strmap_put()`. This isn't how it works though: the strmap will never try to release these keys, and consequently they end up leaking. Fix this leak by initializing the strmap as duplicating its keys and not trying to hand over ownership. The leak is exposed by t5333, but plugging it does not yet make the full test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55e563a commit d0ab663

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pseudo-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void pseudo_merge_group_init(struct pseudo_merge_group *group)
8787
{
8888
memset(group, 0, sizeof(struct pseudo_merge_group));
8989

90-
strmap_init_with_options(&group->matches, NULL, 0);
90+
strmap_init_with_options(&group->matches, NULL, 1);
9191

9292
group->decay = DEFAULT_PSEUDO_MERGE_DECAY;
9393
group->max_merges = DEFAULT_PSEUDO_MERGE_MAX_MERGES;
@@ -275,7 +275,7 @@ static int find_pseudo_merge_group_for_ref(const char *refname,
275275
matches = strmap_get(&group->matches, group_name.buf);
276276
if (!matches) {
277277
matches = xcalloc(1, sizeof(*matches));
278-
strmap_put(&group->matches, strbuf_detach(&group_name, NULL),
278+
strmap_put(&group->matches, group_name.buf,
279279
matches);
280280
}
281281

0 commit comments

Comments
 (0)