From: Duy Nguyen <pclouds@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>,
"Junio C Hamano" <gitster@pobox.com>,
"Michał Górny" <mgorny@gentoo.org>,
"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
Date: Fri, 17 Aug 2018 17:10:12 +0200 [thread overview]
Message-ID: <20180817151012.GA20262@duynguyen.home> (raw)
In-Reply-To: <CACsJy8DH2tESV4xkCYutH=Ye37zGwifGdJhdnNOsRd+JusdOwg@mail.gmail.com>
On Fri, Aug 17, 2018 at 04:36:13PM +0200, Duy Nguyen wrote:
> On Fri, Aug 17, 2018 at 3:05 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
> >
> > Change the few conditional uses of FREE_AND_NULL(x) to be
> > unconditional. As noted in the standard[1] free(NULL) is perfectly
> > valid, so we might as well leave this check up to the C library.
>
> I'm not trying to make you work more on this. But out of curiosity
> would coccinelle help catch this pattern? Szeder's recent work on
> running cocci automatically would help catch all future code like this
> if we could write an spatch.
Just fyi this seems to do the trick. Although I'm nowhere good at
coccinelle to say if we should include this (or something like it)
-- 8< --
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index 4490069df9..f8e018d104 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -16,3 +16,9 @@ expression E;
- free(E);
+ FREE_AND_NULL(E);
- E = NULL;
+
+@@
+expression E;
+@@
+- if (E) { FREE_AND_NULL(E); }
++ FREE_AND_NULL(E);
-- 8< --
--
Duy
next prev parent reply other threads:[~2018-08-17 15:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-17 9:17 [PATCH] gpg-interface.c: Fix potentially freeing NULL values Michał Górny
2018-08-17 9:28 ` Eric Sunshine
2018-08-17 9:40 ` Michał Górny
2018-08-17 13:02 ` [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x) Ævar Arnfjörð Bjarmason
2018-08-17 14:36 ` Duy Nguyen
2018-08-17 15:10 ` Duy Nguyen [this message]
2018-08-17 16:53 ` Junio C Hamano
2018-08-17 17:07 ` Junio C Hamano
2018-08-17 17:33 ` Jeff King
2018-08-17 17:39 ` Jeff King
2018-08-17 17:44 ` Jeff King
2018-08-17 18:29 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180817151012.GA20262@duynguyen.home \
--to=pclouds@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mgorny@gentoo.org \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).