merge-ort: free data structures in merge_finalize()
Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Dec 13, 2020 at 08:04 UTC
89422d29b1d63004683aaa6d11faa65ba734d46f
1 file changed
+31
-1
merge-ort.c
+31
-1
@@ -209,6 +209,16 @@ struct conflict_info {
209
assert((ci) && !(mi)->clean); \
210
} while (0)
211
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
+
222
static int err(struct merge_options *opt, const char *err, ...)
223
{
224
va_list params;
@@ -1153,7 +1163,27 @@ void merge_switch_to_result(struct merge_options *opt,
1163
void merge_finalize(struct merge_options *opt,
1164
struct merge_result *result)
1165
{
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);
1187
}
1188
1189
static void merge_start(struct merge_options *opt, struct merge_result *result)