From 1c41d2805e42d77d943fd3d79ebf5136f74c9ba3 Mon Sep 17 00:00:00 2001 From: Martin Ågren Date: Mon, 21 May 2018 16:54:28 +0200 Subject: unpack_trees_options: free messages when done MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The strings allocated in `setup_unpack_trees_porcelain()` are never freed. Provide a function `clear_unpack_trees_porcelain()` to do so and call it where we use `setup_unpack_trees_porcelain()`. The only non-trivial user is `unpack_trees_start()`, where we should place the new call in `unpack_trees_finish()`. We keep the string pointers in an array, mixing pointers to static memory and memory that we allocate on the heap. We also keep several copies of the individual pointers. So we need to make sure that we do not free what we must not free and that we do not double-free. Let a separate argv_array take ownership of all the strings we create so that we can easily free them. Zero the whole array of string pointers to make sure that we do not leave any dangling pointers. Note that we only take responsibility for the memory allocated in `setup_unpack_trees_porcelain()` and not any other members of the `struct unpack_trees_options`. Helped-by: Junio C Hamano Signed-off-by: Junio C Hamano Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- merge-recursive.c | 1 + 1 file changed, 1 insertion(+) (limited to 'merge-recursive.c') diff --git a/merge-recursive.c b/merge-recursive.c index ddb0fa7369..338f63a952 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -382,6 +382,7 @@ static int unpack_trees_start(struct merge_options *o, static void unpack_trees_finish(struct merge_options *o) { discard_index(&o->orig_index); + clear_unpack_trees_porcelain(&o->unpack_opts); } struct tree *write_tree_from_memory(struct merge_options *o) -- cgit v1.2.3