diff options
author | Jeff King <peff@peff.net> | 2024-06-04 12:13:40 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-05 18:51:43 +0200 |
commit | 6d107751b299e2d0439909d01439b245dd820c5d (patch) | |
tree | 95f30307e17aeba633e6cc5284bbd0ee8503a0f7 /t/t3050-subprojects-fetch.sh | |
parent | sparse-checkout: free string list after displaying (diff) | |
download | git-6d107751b299e2d0439909d01439b245dd820c5d.tar.xz git-6d107751b299e2d0439909d01439b245dd820c5d.zip |
sparse-checkout: free duplicate hashmap entries
In insert_recursive_pattern(), we create a new pattern_entry to insert
into the parent_hashmap. If we find that the same entry already exists
in the hashmap, we skip adding the new one. But we forget to free the new
one, creating a leak.
We can fix it by cleaning up the discarded entry. It would probably be
possible to avoid creating it in the first place, but it's non-trivial.
We'd have to define a "keydata" struct that lets us compare the existing
entries to the broken-out fields. It's probably not worth the
complexity, so we'll punt on that for now.
There is one subtlety here: our insertion is happening in a loop, with
each iteration looking at the pattern we just inserted (hence the
"recursive" in the name). So if we skip insertion, what do we look at?
The obvious answer is that we should remember the existing duplicate we
found and use that. But I _think_ in that case, we probably already have
all of the recursive bits already (from when the original entry was
added). And so just breaking out of the loop would be correct. But I'm
not 100% sure on that; after all, the original leaky code could have
done the same break, but it didn't.
So I went with the "obvious answer" above, which has no chance of
changing the behavior aside from fixing the leak.
With this patch, t1091 can now be marked leak-free.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3050-subprojects-fetch.sh')
0 files changed, 0 insertions, 0 deletions