Skip to content

Commit 9622f8a

Browse files
newrengitster
authored andcommitted
merge-recursive: fix leaks of allocated renames and diff_filepairs
get_renames() has always zero'ed out diff_queued_diff.nr while only manually free'ing diff_filepairs that did not correspond to renames. Further, it allocated struct renames that were tucked away in the return string_list. Make sure all of these are deallocated when we are done with them. Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2dd6f8a commit 9622f8a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

merge-recursive.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,13 +1653,23 @@ static int handle_renames(struct merge_options *o,
16531653
return process_renames(o, ri->head_renames, ri->merge_renames);
16541654
}
16551655

1656-
static void cleanup_renames(struct rename_info *re_info)
1656+
static void cleanup_rename(struct string_list *rename)
16571657
{
1658-
string_list_clear(re_info->head_renames, 0);
1659-
string_list_clear(re_info->merge_renames, 0);
1658+
const struct rename *re;
1659+
int i;
16601660

1661-
free(re_info->head_renames);
1662-
free(re_info->merge_renames);
1661+
for (i = 0; i < rename->nr; i++) {
1662+
re = rename->items[i].util;
1663+
diff_free_filepair(re->pair);
1664+
}
1665+
string_list_clear(rename, 1);
1666+
free(rename);
1667+
}
1668+
1669+
static void cleanup_renames(struct rename_info *re_info)
1670+
{
1671+
cleanup_rename(re_info->head_renames);
1672+
cleanup_rename(re_info->merge_renames);
16631673
}
16641674

16651675
static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)

0 commit comments

Comments
 (0)