merge-recursive: fix leaks of allocated renames and diff_filepairs
authorElijah Newren <newren@gmail.com>
Thu, 19 Apr 2018 17:58:01 +0000 (10:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Apr 2018 01:44:15 +0000 (10:44 +0900)
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>
merge-recursive.c
index 40e142efdb9d37dc7370f24af1580a34ca1f4fb8..fc96653f6322d666d0c59f90bbfeb38cd28c681a 100644 (file)
@@ -1663,13 +1663,23 @@ static int handle_renames(struct merge_options *o,
        return process_renames(o, ri->head_renames, ri->merge_renames);
 }
 
        return process_renames(o, ri->head_renames, ri->merge_renames);
 }
 
-static void cleanup_renames(struct rename_info *re_info)
+static void cleanup_rename(struct string_list *rename)
 {
 {
-       string_list_clear(re_info->head_renames, 0);
-       string_list_clear(re_info->merge_renames, 0);
+       const struct rename *re;
+       int i;
 
 
-       free(re_info->head_renames);
-       free(re_info->merge_renames);
+       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)
+{
+       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)
 }
 
 static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)