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

[PATCH 2/4] Fix use-after-free warning with GCC at -O3

From
Mike Hommey <mh@glandium.org>
Date
Jun 3, 2025, 23:06 UTC
Message-ID
<20250603230646.2322671-2-mh@glandium.org>
In-Reply-To
<20250603230646.2322671-1-mh@glandium.org>
```
reftable/basics.c: In function ‘parse_names’:
reftable/basics.c:233:17: error: pointer ‘names’ may be used after ‘free’ [-Werror=use-after-free]
  233 |                 reftable_free(names[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~
In function ‘reftable_free’,
    inlined from ‘reftable_realloc’ at reftable/basics.c:30:3,
    inlined from ‘reftable_realloc’ at reftable/basics.c:27:7,
    inlined from ‘reftable_alloc_grow’ at reftable/basics.h:228:10,
    inlined from ‘parse_names’ at reftable/basics.c:214:8:
reftable/basics.c:44:17: note: call to ‘free’ here
   44 |                 free(p);
      |                 ^~~~~~~
```
Signed-off-by: Mike Hommey <mh@glandium.org>
---
 reftable/basics.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/reftable/basics.c b/reftable/basics.c
index 9988ebd635..de21fe6ef7 100644
--- a/reftable/basics.c
+++ b/reftable/basics.c
@@ -229,9 +229,11 @@ char **parse_names(char *buf, int size)
 	return names;
 
 err:
-	for (size_t i = 0; i < names_len; i++)
-		reftable_free(names[i]);
-	reftable_free(names);
+	if (names) {
+		for (size_t i = 0; i < names_len; i++)
+			reftable_free(names[i]);
+		reftable_free(names);
+	}
 	return NULL;
 }
 
-- 
2.50.0.rc1.593.g042f21cb9b
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 11 in “Fix maybe-uninitialized warning with GCC at -O3”
  1. 1/4 Fix maybe-uninitialized warning with GCC at -O3Mike Hommey, Jun 3, 2025
  2. 4/4 Fix unreachable-code warning with clang on WindowsMike Hommey, Jun 3, 2025
  3. Patrick SteinhardtJun 4, 2025
  4. Junio C HamanoJun 4, 2025
  5. 3/4 Fix comma warnings with clang on WindowsMike Hommey, Jun 3, 2025
  6. Junio C HamanoJun 3, 2025
  7. 2/4 Fix use-after-free warning with GCC at -O3Mike Hommey, Jun 3, 2025
  8. Junio C HamanoJun 3, 2025
  9. Patrick SteinhardtJun 4, 2025
  10. Patrick SteinhardtJun 4, 2025
  11. Jeff KingJun 6, 2025

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.