git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] reftable: use xmalloc() and xrealloc()
@ 2024-04-06 20:37 René Scharfe
  2024-04-08  5:44 ` Patrick Steinhardt
  0 siblings, 1 reply; 7+ messages in thread
From: René Scharfe @ 2024-04-06 20:37 UTC (permalink / raw)
  To: Git List; +Cc: Han-Wen Nienhuys, Patrick Steinhardt

malloc(3) and realloc(3) can fail and return NULL.  None of the reftable
code checks for that possibility and would happily dereference NULL
pointers.  Use xmalloc() and xrealloc() instead like in the rest of Git
to report allocation errors and exit cleanly, and to also honor the
environment variable GIT_ALLOC_LIMIT.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 reftable/publicbasics.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/reftable/publicbasics.c b/reftable/publicbasics.c
index 44b84a125e..f33a65df34 100644
--- a/reftable/publicbasics.c
+++ b/reftable/publicbasics.c
@@ -19,14 +19,14 @@ void *reftable_malloc(size_t sz)
 {
 	if (reftable_malloc_ptr)
 		return (*reftable_malloc_ptr)(sz);
-	return malloc(sz);
+	return xmalloc(sz);
 }

 void *reftable_realloc(void *p, size_t sz)
 {
 	if (reftable_realloc_ptr)
 		return (*reftable_realloc_ptr)(p, sz);
-	return realloc(p, sz);
+	return xrealloc(p, sz);
 }

 void reftable_free(void *p)
--
2.44.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-09  3:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-06 20:37 [PATCH] reftable: use xmalloc() and xrealloc() René Scharfe
2024-04-08  5:44 ` Patrick Steinhardt
2024-04-08 15:42   ` Junio C Hamano
2024-04-08 16:33     ` Patrick Steinhardt
2024-04-08 17:50   ` Han-Wen Nienhuys
2024-04-08 20:36     ` Junio C Hamano
2024-04-09  3:24     ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).