Thread (49 messages) flat view 49 messages, 6 authors, 13d ago

Re: [PATCH v2 2/4] mktree: plug per-tree leak in --batch mode

From: Jeff King <hidden>
Date: 2026-08-27 05:36:05

On Tue, Aug 25, 2026 at 07:00:27PM +0000, Elijah Newren via GitGitGadget wrote:
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.
Yikes. It is sad that we did not catch this in our leak-checking builds,
as it implies that we do not test "mktree --batch" with multiple inputs.
Or grepping for "mktree.*--batch" implies that we do not test the
feature at all!

Looks like that feature comes from f1cf2d8b14 (mktree --batch: build
more than one tree object, 2009-05-14), so I am not surprised that test
coverage was a bit more spotty back then.

I guess you are going to add some coverage incidentally (or else you
would not have found this). That's better than nothing, but I suspect a
few basic directed "mktree --batch" tests would be a good thing to have
in t1010.

#leftoverbits, perhaps?

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help