All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] bisect: fix memory leak and document `find_bisection()`
@ 2017-11-01 20:34 Martin Ågren
  2017-11-01 20:34 ` [PATCH 2/3] bisect: fix off-by-one error in `best_bisection_sorted()` Martin Ågren
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Martin Ågren @ 2017-11-01 20:34 UTC (permalink / raw)
  To: git; +Cc: Christian Couder

`find_bisection()` rebuilds the commit list it is given by reversing it
and skipping uninteresting commits. The uninteresting list entries are
leaked. Free them to fix the leak.

While we're here and understand what's going on, document the function.
In particular, make sure to document that the original list should not
be examined by the caller.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 bisect.c | 4 +++-
 bisect.h | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/bisect.c b/bisect.c
index 96beeb5d1..f9de4f2e8 100644
--- a/bisect.c
+++ b/bisect.c
@@ -380,8 +380,10 @@ struct commit_list *find_bisection(struct commit_list *list,
 		unsigned flags = p->item->object.flags;
 
 		next = p->next;
-		if (flags & UNINTERESTING)
+		if (flags & UNINTERESTING) {
+			free(p);
 			continue;
+		}
 		p->next = last;
 		last = p;
 		if (!(flags & TREESAME))
diff --git a/bisect.h b/bisect.h
index acd12ef80..cf135f16e 100644
--- a/bisect.h
+++ b/bisect.h
@@ -1,6 +1,13 @@
 #ifndef BISECT_H
 #define BISECT_H
 
+/*
+ * Find bisection. If something is found, `reaches` will be the number of
+ * commits that the best commit reaches. `all` will be the count of
+ * non-SAMETREE commits. If `find_all` is set, all non-SAMETREE commits are
+ * returned sorted, otherwise only a single best commit is returned. The
+ * original list will be left in an undefined state and should not be examined.
+ */
 extern struct commit_list *find_bisection(struct commit_list *list,
 					  int *reaches, int *all,
 					  int find_all);
-- 
2.15.0.415.gac1375d7e


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

end of thread, other threads:[~2017-11-05 20:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-01 20:34 [PATCH 1/3] bisect: fix memory leak and document `find_bisection()` Martin Ågren
2017-11-01 20:34 ` [PATCH 2/3] bisect: fix off-by-one error in `best_bisection_sorted()` Martin Ågren
2017-11-01 20:34 ` [PATCH 3/3] bisect: fix memory leak when returning best element Martin Ågren
2017-11-02  4:54 ` [PATCH 1/3] bisect: fix memory leak and document `find_bisection()` Junio C Hamano
2017-11-02 10:47   ` Martin Ågren
2017-11-05 20:24     ` [PATCH v2 0/4] bisect: assorted leak-fixes Martin Ågren
2017-11-05 20:24       ` [PATCH v2 1/4] bisect: change calling-convention of `find_bisection()` Martin Ågren
2017-11-05 20:24       ` [PATCH v2 2/4] bisect: fix memory leak in `find_bisection()` Martin Ågren
2017-11-05 20:24       ` [PATCH v2 3/4] bisect: fix off-by-one error in `best_bisection_sorted()` Martin Ågren
2017-11-05 20:24       ` [PATCH v2 4/4] bisect: fix memory leak when returning best element 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.