Skip to content

Commit 89422d2

Browse files
newrengitster
authored andcommitted
merge-ort: free data structures in merge_finalize()
Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef2b369 commit 89422d2

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

merge-ort.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ struct conflict_info {
209209
assert((ci) && !(mi)->clean); \
210210
} while (0)
211211

212+
static void free_strmap_strings(struct strmap *map)
213+
{
214+
struct hashmap_iter iter;
215+
struct strmap_entry *entry;
216+
217+
strmap_for_each_entry(map, &iter, entry) {
218+
free((char*)entry->key);
219+
}
220+
}
221+
212222
static int err(struct merge_options *opt, const char *err, ...)
213223
{
214224
va_list params;
@@ -1153,7 +1163,27 @@ void merge_switch_to_result(struct merge_options *opt,
11531163
void merge_finalize(struct merge_options *opt,
11541164
struct merge_result *result)
11551165
{
1156-
die("Not yet implemented");
1166+
struct merge_options_internal *opti = result->priv;
1167+
1168+
assert(opt->priv == NULL);
1169+
1170+
/*
1171+
* We marked opti->paths with strdup_strings = 0, so that we
1172+
* wouldn't have to make another copy of the fullpath created by
1173+
* make_traverse_path from setup_path_info(). But, now that we've
1174+
* used it and have no other references to these strings, it is time
1175+
* to deallocate them.
1176+
*/
1177+
free_strmap_strings(&opti->paths);
1178+
strmap_clear(&opti->paths, 1);
1179+
1180+
/*
1181+
* All keys and values in opti->conflicted are a subset of those in
1182+
* opti->paths. We don't want to deallocate anything twice, so we
1183+
* don't free the keys and we pass 0 for free_values.
1184+
*/
1185+
strmap_clear(&opti->conflicted, 0);
1186+
FREE_AND_NULL(opti);
11571187
}
11581188

11591189
static void merge_start(struct merge_options *opt, struct merge_result *result)

0 commit comments

Comments
 (0)