All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] diff-lib: clear `pending` object-array in `index_differs_from()`
@ 2017-09-20 19:47 Martin Ågren
  2017-09-20 20:02 ` Jeff King
  0 siblings, 1 reply; 27+ messages in thread
From: Martin Ågren @ 2017-09-20 19:47 UTC (permalink / raw)
  To: git; +Cc: Stephan Beyer

Instead of conditionally freeing `rev.pending.objects`, just call
`object_array_clear()` on `rev.pending`. This means we don't poke as
much into the implementation, which is already a good thing, but also
that we free the individual entries as well, thereby fixing a
memory-leak.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 diff-lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index 2a52b07..4e0980c 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -549,7 +549,6 @@ int index_differs_from(const char *def, int diff_flags,
 	rev.diffopt.flags |= diff_flags;
 	rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
 	run_diff_index(&rev, 1);
-	if (rev.pending.alloc)
-		free(rev.pending.objects);
+	object_array_clear(&rev.pending);
 	return (DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0);
 }
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2017-10-01 15:04 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 19:47 [PATCH] diff-lib: clear `pending` object-array in `index_differs_from()` Martin Ågren
2017-09-20 20:02 ` Jeff King
2017-09-21  3:56   ` Martin Ågren
2017-09-21  4:52     ` Jeff King
2017-09-22 23:34   ` [PATCH v2 0/6] reroll ma/plugleaks; more `object_array`-fixes Martin Ågren
2017-09-22 23:34     ` [PATCH v2 1/6] builtin/commit: fix memory leak in `prepare_index()` Martin Ågren
2017-09-22 23:34     ` [PATCH v2 2/6] commit: fix memory leak in `reduce_heads()` Martin Ågren
2017-09-22 23:34     ` [PATCH v2 3/6] leak_pending: use `object_array_clear()`, not `free()` Martin Ågren
2017-09-23  3:47       ` Jeff King
2017-09-22 23:34     ` [PATCH v2 4/6] object_array: " Martin Ågren
2017-09-23  4:04       ` Jeff King
2017-09-23  9:41         ` Martin Ågren
2017-09-22 23:34     ` [PATCH v2 5/6] object_array: add and use `object_array_pop()` Martin Ågren
2017-09-23  4:27       ` Jeff King
2017-09-23  9:49         ` Martin Ågren
2017-09-23 15:47           ` Jeff King
2017-09-22 23:34     ` [PATCH v2 6/6] pack-bitmap[-write]: use `object_array_clear()`, don't leak Martin Ågren
2017-09-23  4:35       ` Jeff King
2017-09-23  4:37     ` [PATCH v2 0/6] reroll ma/plugleaks; more `object_array`-fixes Jeff King
2017-09-23  9:54       ` Martin Ågren
2017-09-23 16:13         ` Jeff King
2017-09-23 16:38           ` Jeff King
2017-09-24 19:59             ` Martin Ågren
2017-09-25 16:08               ` Jeff King
2017-10-01 15:04                 ` Martin Ågren
2017-09-24  7:01     ` Junio C Hamano
2017-09-24 20:00       ` Martin Ågren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.