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 <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren 2018-02-14 10:51:51 -08:00 коммит произвёл Junio C Hamano
Родитель 2dd6f8aa84
Коммит 9622f8af8c
1 изменённых файлов: 15 добавлений и 5 удалений

Просмотреть файл

@ -1653,13 +1653,23 @@ static int handle_renames(struct merge_options *o,
return process_renames(o, ri->head_renames, ri->merge_renames);
}
static void cleanup_rename(struct string_list *rename)
{
const struct rename *re;
int i;
for (i = 0; i < rename->nr; i++) {
re = rename->items[i].util;
diff_free_filepair(re->pair);
}
string_list_clear(rename, 1);
free(rename);
}
static void cleanup_renames(struct rename_info *re_info)
{
string_list_clear(re_info->head_renames, 0);
string_list_clear(re_info->merge_renames, 0);
free(re_info->head_renames);
free(re_info->merge_renames);
cleanup_rename(re_info->head_renames);
cleanup_rename(re_info->merge_renames);
}
static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)