threads / patch / 46792

patchcommit: fix memory leak in `reduce_heads()`

Subject: [PATCH] commit: fix memory leak in `reduce_heads()`

## tl;dr

3 messages between Sep 20, 2017 and Sep 20, 2017. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Martin Ågren· Sep 20, 2017, 19:47 UTC · lore

We don't free the temporary scratch space we use with `remove_redundant()`. Free it similar to how we do it in `get_merge_bases_many_0()`.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 commit.c | 1 +
 1 file changed, 1 insertion(+)
Show changes to commit.c +1 −0
diff --git a/commit.c b/commit.c
index 9062980..1e0e633 100644
--- a/commit.c
+++ b/commit.c
@@ -1086,6 +1086,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
 	num_head = remove_redundant(array, num_head);
 	for (i = 0; i < num_head; i++)
 		tail = &commit_list_insert(array[i], tail)->next;
+	free(array);
 	return result;
 }
 
-- 
2.14.1
Jeff King· Sep 20, 2017, 20:15 UTC · re: Martin Ågren · lore

Re: [PATCH] commit: fix memory leak in `reduce_heads()`

On Wed, Sep 20, 2017 at 09:47:25PM +0200, Martin Ågren wrote:
> We don't free the temporary scratch space we use with
> `remove_redundant()`. Free it similar to how we do it in
> `get_merge_bases_many_0()`.

Yep, seems very straightforward, and there are no code paths where we wouldn't want this.

-Peff
Jonathan Nieder· Sep 20, 2017, 21:34 UTC · re: Martin Ågren · lore

Re: [PATCH] commit: fix memory leak in `reduce_heads()`

Martin Ågren wrote:
Show 8 quoted lines
> We don't free the temporary scratch space we use with
> `remove_redundant()`. Free it similar to how we do it in
> `get_merge_bases_many_0()`.
>
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
>  commit.c | 1 +
>  1 file changed, 1 insertion(+)
Good catch.  Thanks.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

← back to recent threads