All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cocci: detect useless free(3) calls
@ 2017-02-11 13:58 René Scharfe
  2017-02-11 19:01 ` Junio C Hamano
  2017-02-11 19:31 ` Lars Schneider
  0 siblings, 2 replies; 4+ messages in thread
From: René Scharfe @ 2017-02-11 13:58 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Pranit Bauva

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] cocci: detect useless free(3) calls
  2017-02-11 13:58 [PATCH] cocci: detect useless free(3) calls René Scharfe
@ 2017-02-11 19:01 ` Junio C Hamano
  2017-02-11 19:31 ` Lars Schneider
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2017-02-11 19:01 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Pranit Bauva

René Scharfe <l.s.r@web.de> writes:

> 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.

Thanks.  This should have been caught by code inspection, but
having automated way to do so is always good.

>
>  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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cocci: detect useless free(3) calls
  2017-02-11 13:58 [PATCH] cocci: detect useless free(3) calls René Scharfe
  2017-02-11 19:01 ` Junio C Hamano
@ 2017-02-11 19:31 ` Lars Schneider
  2017-02-11 19:50   ` René Scharfe
  1 sibling, 1 reply; 4+ messages in thread
From: Lars Schneider @ 2017-02-11 19:31 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano, Pranit Bauva


> On 11 Feb 2017, at 14:58, René Scharfe <l.s.r@web.de> wrote:
> 
> 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.

Hi Rene,

how do you run these checks on the entire Git source?
Do you run each semantic patch file on the source like this?

spatch --sp-file contrib/coccinelle/qsort.cocci --dir /path/to/git/git
...
spatch --sp-file contrib/coccinelle/free.cocci --dir /path/to/git/git

How stable do you consider these checks? Would it make sense to run them
as part of the Travis-CI build [1]? 

Thanks,
Lars

[1] https://travis-ci.org/git/git/branches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cocci: detect useless free(3) calls
  2017-02-11 19:31 ` Lars Schneider
@ 2017-02-11 19:50   ` René Scharfe
  0 siblings, 0 replies; 4+ messages in thread
From: René Scharfe @ 2017-02-11 19:50 UTC (permalink / raw)
  To: Lars Schneider; +Cc: Git List, Junio C Hamano, Pranit Bauva

Am 11.02.2017 um 20:31 schrieb Lars Schneider:
> how do you run these checks on the entire Git source?
> Do you run each semantic patch file on the source like this?
> 
> spatch --sp-file contrib/coccinelle/qsort.cocci --dir /path/to/git/git
> ...
> spatch --sp-file contrib/coccinelle/free.cocci --dir /path/to/git/git

With "make coccicheck", which runs spatch against the items in the make
variable C_SOURCES, for all .cocci files.

> How stable do you consider these checks? Would it make sense to run them
> as part of the Travis-CI build [1]? 

There seem to have been problems with older versions[2], but I'm not
aware of other issues.

Having these checks run automatically would be nice because they
require a special tool which I guess not everybody is willing (or able)
to install and because they take multiple minutes.

René


[2] https://public-inbox.org/git/014ef44e-9dd8-40b3-a3ec-b483f938ee02@web.de/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-11 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-11 13:58 [PATCH] cocci: detect useless free(3) calls René Scharfe
2017-02-11 19:01 ` Junio C Hamano
2017-02-11 19:31 ` Lars Schneider
2017-02-11 19:50   ` René Scharfe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.