@@ -81,6 +81,16 @@ static int err(struct merge_options *opt, const char *err, ...)
return -1;
}
+static void free_strmap_strings(struct strmap *map)
+{
+ struct hashmap_iter iter;
+ struct strmap_entry *entry;
+
+ strmap_for_each_entry(map, &iter, entry) {
+ free((char*)entry->key);
+ }
+}
+
static void setup_path_info(struct merge_options *opt,
struct string_list_item *result,
const char *current_dir_name,
@@ -839,7 +849,27 @@ void merge_switch_to_result(struct merge_options *opt,
void merge_finalize(struct merge_options *opt,
struct merge_result *result)
{
- die("Not yet implemented");
+ struct merge_options_internal *opti = result->priv;
+
+ assert(opt->priv == NULL);
+
+ /*
+ * We marked opti->paths with strdup_strings = 0, so that we
+ * wouldn't have to make another copy of the fullpath created by
+ * make_traverse_path from setup_path_info(). But, now that we've
+ * used it and have no other references to these strings, it is time
+ * to deallocate them.
+ */
+ free_strmap_strings(&opti->paths);
+ strmap_clear(&opti->paths, 1);
+
+ /*
+ * All strings and util fields in opti->unmerged are a subset of
+ * those in opti->paths. We don't want to deallocate anything
+ * twice, so we don't free the strings we pass 0 for free_util.
+ */
+ strmap_clear(&opti->unmerged, 0);
+ FREE_AND_NULL(opti);
}
static void merge_start(struct merge_options *opt, struct merge_result *result)
Signed-off-by: Elijah Newren <newren@gmail.com> --- merge-ort.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)