Skip to content

Commit e336bdc

Browse files
Kevin Willfordgitster
authored andcommitted
merge-recursive: fix memory leak
In merge_trees if process_renames or process_entry returns less than zero, the method will just return and not free re_merge, re_head, or entries. This change cleans up the allocated variables before returning to the caller. Signed-off-by: Kevin Willford <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edc74bc commit e336bdc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

merge-recursive.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,16 +1956,18 @@ int merge_trees(struct merge_options *o,
19561956
re_merge = get_renames(o, merge, common, head, merge, entries);
19571957
clean = process_renames(o, re_head, re_merge);
19581958
if (clean < 0)
1959-
return clean;
1959+
goto cleanup;
19601960
for (i = entries->nr-1; 0 <= i; i--) {
19611961
const char *path = entries->items[i].string;
19621962
struct stage_data *e = entries->items[i].util;
19631963
if (!e->processed) {
19641964
int ret = process_entry(o, path, e);
19651965
if (!ret)
19661966
clean = 0;
1967-
else if (ret < 0)
1968-
return ret;
1967+
else if (ret < 0) {
1968+
clean = ret;
1969+
goto cleanup;
1970+
}
19691971
}
19701972
}
19711973
for (i = 0; i < entries->nr; i++) {
@@ -1975,13 +1977,17 @@ int merge_trees(struct merge_options *o,
19751977
entries->items[i].string);
19761978
}
19771979

1980+
cleanup:
19781981
string_list_clear(re_merge, 0);
19791982
string_list_clear(re_head, 0);
19801983
string_list_clear(entries, 1);
19811984

19821985
free(re_merge);
19831986
free(re_head);
19841987
free(entries);
1988+
1989+
if (clean < 0)
1990+
return clean;
19851991
}
19861992
else
19871993
clean = 1;

0 commit comments

Comments
 (0)