git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] reftable: use xmalloc() and xrealloc()

From
René Scharfe <l.s.r@web.de>
Date
Apr 6, 2024, 20:37 UTC
Message-ID
<963961ee-0f1d-42b8-8dda-5838e7a2ed94@web.de>

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
Next: Patrick Steinhardt
Message 1 of 7 in “reftable: use xmalloc() and xrealloc()”
  1. reftable: use xmalloc() and xrealloc()René Scharfe, Apr 6, 2024
  2. Patrick SteinhardtApr 8, 2024
  3. Junio C HamanoApr 8, 2024
  4. Patrick SteinhardtApr 8, 2024
  5. Han-Wen NienhuysApr 8, 2024
  6. Junio C HamanoApr 8, 2024
  7. Patrick SteinhardtApr 9, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.