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

[PATCH] cocci: detect useless free(3) calls

From
René Scharfe <l.s.r@web.de>
Date
Feb 11, 2017, 13:58 UTC
Message-ID
<7e10f934-f084-ceb4-00eb-b75cdb01886b@web.de>

Add a semantic patch for removing checks that cause free(3) to only be called with a NULL pointer, as that must be a programming mistake.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
No cases are found in master or next, but 1d263b93 (bisect--helper:
`bisect_next_check` & bisect_voc shell function in C) introduced four
of them to pu.
 contrib/coccinelle/free.cocci | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index e28213161a..c03ba737e5 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -3,3 +3,9 @@ expression E;
 @@
 - if (E)
   free(E);
+
+@@
+expression E;
+@@
+- if (!E)
+  free(E);
-- 
2.11.1
Next: Junio C Hamano
Message 1 of 4 in “cocci: detect useless free(3) calls”
  1. cocci: detect useless free(3) callsRené Scharfe, Feb 11, 2017
  2. Junio C HamanoFeb 11, 2017
  3. Lars SchneiderFeb 11, 2017
  4. René ScharfeFeb 11, 2017

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.