Re: [PATCH v2 2/4] mktree: plug per-tree leak in --batch mode
- From
Jeff King <peff@peff.net>
- Date
- Aug 27, 2026, 05:36 UTC
- Message-ID
- <20260827053602.GA189659@coredump.intra.peff.net>
- In-Reply-To
- <3f3b75690eea02960c7edc8d318ce7dff654f1bc.1787684429.git.gitgitgadget@gmail.com>
On Tue, Aug 25, 2026 at 07:00:27PM +0000, Elijah Newren via GitGitGadget wrote:
Show 9 quoted lines
> 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