]> git.ipfire.org Git - thirdparty/git.git/commit
reftable: avoid leaks on realloc error
authorRené Scharfe <l.s.r@web.de>
Sat, 28 Dec 2024 09:47:05 +0000 (10:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 28 Dec 2024 16:00:44 +0000 (08:00 -0800)
commit8db127d43f5b0eff254a851f9c966b7b85d91992
tree8c7cd2c2a66573512ade8f4e80f5af8e88fe1e4b
parent76cf4f61c87855ebf0784b88aaf737d6b09f504b
reftable: avoid leaks on realloc error

When realloc(3) fails, it returns NULL and keeps the original allocation
intact.  REFTABLE_ALLOC_GROW overwrites both the original pointer and
the allocation count variable in that case, simultaneously leaking the
original allocation and misrepresenting the number of storable items.

parse_names() and reftable_buf_add() avoid leaking by restoring the
original pointer value on failure, but all other callers seem to be OK
with losing the old allocation.  Add a new variant of the macro,
REFTABLE_ALLOC_GROW_OR_NULL, which plugs the leak and zeros the
allocation counter.  Use it for those callers.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/basics.h
reftable/block.c
reftable/pq.c
reftable/record.c
reftable/stack.c
reftable/writer.c
t/unit-tests/t-reftable-basics.c