diff mbox series

[03/26] bisect: fix leaking string in `handle_bad_merge_base()`

Message ID 4a554ab10409e4cfb3c42b817cae3d026284663c.1730901926.git.ps@pks.im (mailing list archive)
State New
Headers show
Series [01/26] builtin/blame: fix leaking blame entries with `--incremental` | expand

Commit Message

Patrick Steinhardt Nov. 6, 2024, 3:10 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 9c52241050c..e9e603877eb 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;
 	}