merge-recursive: fix leaks of allocated renames and diff_filepairs
[gitweb.git] / merge-recursive.c
index 35c0470eac2bb00d42b0b4303aab0837114e4137..c24b8f3de4c3b28667694086359a01bbaf2bc5a9 100644 (file)
@@ -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_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)