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 <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Elijah Newren 2026-08-29 07:00:29 +00:00 committed by Junio C Hamano
parent b6f5e80fdf
commit 6272f3bd17
1 changed files with 3 additions and 0 deletions

View File

@ -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;