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

[PATCH] cocci: FREE_AND_NULL(E) is safe to call on NULL

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 11, 2026, 22:21 UTC
Message-ID
<xmqqh5jv8m4w.fsf@gitster.g>
In-Reply-To
<xmqqld978mok.fsf@gitster.g>

Just like we allow calling free(E) without checking if E is not NULL, it is safe to call FREE_AND_NULL(E) unconditionally.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 tools/coccinelle/free.cocci | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/tools/coccinelle/free.cocci b/tools/coccinelle/free.cocci
index 3dfaae9dd8..f2af140cfb 100644
--- a/tools/coccinelle/free.cocci
+++ b/tools/coccinelle/free.cocci
@@ -6,6 +6,8 @@ expression E;
   free(E);
 |
   commit_list_free(E);
+|
+  FREE_AND_NULL(E);
 )
 
 @@
-- 
2.56.0-rc0-143-g1fea62d0ca
Previous: Junio C HamanoNext: René Scharfe
Message 2 of 5 in “cocci: remove risky "if (!E) free(E)" conversion”
  1. cocci: remove risky "if (!E) free(E)" conversionJunio C Hamano, Sep 11, 2026
  2. cocci: FREE_AND_NULL(E) is safe to call on NULLJunio C Hamano, Sep 11, 2026
  3. René ScharfeSep 12, 2026
  4. Junio C HamanoSep 12, 2026
  5. René ScharfeSep 13, 2026

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.