Skip to content

Commit 3d31d38

Browse files
pks-tgitster
authored andcommitted
merge-recursive: fix leaking rename conflict info
When computing rename conflicts in our recursive merge algorithm we set up `struct rename_conflict_info`s to track that information. We never free those data structures though and thus leak memory. We need to be a bit more careful here though because the same rename conflict info can be assigned to multiple structures. Accommodate for this by introducing a `rename_conflict_info_owned` bit that we can use to steer whether or not the rename conflict info shall be free'd. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent afb0653 commit 3d31d38

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

merge-recursive.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ enum rename_type {
239239
struct stage_data {
240240
struct diff_filespec stages[4]; /* mostly for oid & mode; maybe path */
241241
struct rename_conflict_info *rename_conflict_info;
242-
unsigned processed:1;
242+
unsigned processed:1,
243+
rename_conflict_info_owned:1;
243244
};
244245

245246
struct rename {
@@ -308,6 +309,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
308309

309310
ci->ren1->dst_entry->processed = 0;
310311
ci->ren1->dst_entry->rename_conflict_info = ci;
312+
ci->ren1->dst_entry->rename_conflict_info_owned = 1;
311313
if (ren2) {
312314
ci->ren2->dst_entry->rename_conflict_info = ci;
313315
}
@@ -3055,6 +3057,10 @@ static void final_cleanup_rename(struct string_list *rename)
30553057
for (i = 0; i < rename->nr; i++) {
30563058
re = rename->items[i].util;
30573059
diff_free_filepair(re->pair);
3060+
if (re->src_entry->rename_conflict_info_owned)
3061+
FREE_AND_NULL(re->src_entry->rename_conflict_info);
3062+
if (re->dst_entry->rename_conflict_info_owned)
3063+
FREE_AND_NULL(re->dst_entry->rename_conflict_info);
30583064
}
30593065
string_list_clear(rename, 1);
30603066
free(rename);

t/t3401-rebase-and-am-rename.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git rebase + directory rename tests'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67
. "$TEST_DIRECTORY"/lib-rebase.sh
78

t/t4153-am-resume-override-opts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git-am command-line options override saved options'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67
. "$TEST_DIRECTORY"/lib-terminal.sh
78

t/t7201-co.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Test switching across them.
2323
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
2424
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
2525

26+
TEST_PASSES_SANITIZE_LEAK=true
2627
. ./test-lib.sh
2728

2829
test_tick

0 commit comments

Comments
 (0)