Skip to content

Commit ed78f04

Browse files
pks-tgitster
authored andcommitted
merge-ort: fix two leaks when handling directory rename modifications
There are two leaks in `apply_directory_rename_modifications()`: - We do not release the `dirs_to_insert` string list. - We do not release some `conflict_info` we put into the `opt->priv->paths` string map. The former is trivial to fix. The latter is a bit less straight forward: the `util` pointer of the string map may sometimes point to data that has been allocated via `CALLOC()`, while at other times it may point to data that has been allocated via a `mem_pool`. It very much seems like an oversight that we didn't also allocate the conflict info in this code path via the memory pool, though. So let's fix that, which will also plug the memory leak for us. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a01470 commit ed78f04

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

merge-ort.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
27102710
struct conflict_info *dir_ci;
27112711
char *cur_dir = dirs_to_insert.items[i].string;
27122712

2713-
CALLOC_ARRAY(dir_ci, 1);
2713+
dir_ci = mem_pool_calloc(&opt->priv->pool, 1, sizeof(*dir_ci));
27142714

27152715
dir_ci->merged.directory_name = parent_name;
27162716
len = strlen(parent_name);
@@ -2838,6 +2838,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
28382838
* Finally, record the new location.
28392839
*/
28402840
pair->two->path = new_path;
2841+
2842+
string_list_clear(&dirs_to_insert, 0);
28412843
}
28422844

28432845
/*** Function Grouping: functions related to regular rename detection ***/

t/t6423-merge-rename-directories.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test_description="recursive merge with directory renames"
2525
# underscore notation is to differentiate different
2626
# files that might be renamed into each other's paths.)
2727

28+
TEST_PASSES_SANITIZE_LEAK=true
2829
. ./test-lib.sh
2930
. "$TEST_DIRECTORY"/lib-merge.sh
3031

0 commit comments

Comments
 (0)