Re: [PATCH v4 4/6] coccinelle: add a rule to make "expression" code use FREE_AND_NULL()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 16, 2017, 19:43 UTC
- Message-ID
- <xmqq7f0byayu.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170615231549.20085-5-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 6 quoted lines
> A follow-up to the existing "type" rule added in an earlier > change. This catches some occurrences that are missed by the previous > rule. > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > ---
Hmph, I wonder if the "type" thing is really needed. Over there, "ptr" is an expression and we can find "free(ptr); ptr = NULL" with the rule in this patch already, no?
In any case, I'll queue these patches as-is. Thanks for working on this.
Show 18 quoted lines
> contrib/coccinelle/free.cocci | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci > index 35fb992621..f2d97e755b 100644 > --- a/contrib/coccinelle/free.cocci > +++ b/contrib/coccinelle/free.cocci > @@ -17,3 +17,10 @@ T *ptr; > - free(ptr); > - ptr = NULL; > + FREE_AND_NULL(ptr); > + > +@@ > +expression E; > +@@ > +- free(E); > +- E = NULL; > ++ FREE_AND_NULL(E);