From 6272f3bd174fcd1b394d8b5e05b2ba384bd9f63e Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 29 Aug 2026 07:00:29 +0000 Subject: [PATCH] mktree: plug per-tree leak in --batch mode In --batch mode "git mktree" reuses its entry buffer across trees, resetting `used` to 0 after writing each tree. It never frees the `treeent` structures the previous tree appended, though, so once the next tree overwrites those slots the earlier allocations are leaked. A single-tree invocation hides this, as the entries stay reachable through the `entries` global until exit. Free each entry when resetting the buffer, and free the buffer itself before returning. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/mktree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/mktree.c b/builtin/mktree.c index 4084e32476..dc2d293c3d 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -200,8 +200,11 @@ int cmd_mktree(int ac, puts(oid_to_hex(&oid)); fflush(stdout); } + for (int i = 0; i < used; i++) + free(entries[i]); used=0; /* reset tree entry buffer for re-use in batch mode */ } + free(entries); strbuf_release(&sb); return 0;