diff mbox series

[v3,03/27] bisect: fix leaking string in `handle_bad_merge_base()`

Message ID 20241120-b4-pks-leak-fixes-pt10-v3-3-d67f08f45c74@pks.im (mailing list archive)
State New
Headers show
Series Memory leak fixes (pt.10, final) | expand

Commit Message

Patrick Steinhardt Nov. 20, 2024, 1:39 p.m. UTC
When handling a bad merge base we print an error, which includes the set
of good revisions joined by spaces. This string is allocated, but never
freed.

Fix this memory leak. Note that the local `bad_hex` varible also looks
like a string that we should free. But in fact, `oid_to_hex()` returns
an address to a static variable even though it is declared to return a
non-constant string. The function signature is thus quite misleading and
really should be fixed, but doing so is outside of the scope of this
patch series.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 bisect.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/bisect.c b/bisect.c
index 9c52241050c14ecbf3f7950a0c5e7b962fcaa541..e9e603877eba059c878ff92bc11dd84553d0649e 100644
--- a/bisect.c
+++ b/bisect.c
@@ -801,6 +801,8 @@  static enum bisect_error handle_bad_merge_base(void)
 				"between %s and [%s].\n"),
 				bad_hex, term_bad, term_good, bad_hex, good_hex);
 		}
+
+		free(good_hex);
 		return BISECT_MERGE_BASE_CHECK;
 	}