{"thread":{"id":"45113","subject":"[PATCH] cocci: detect useless free(3) calls","startedAt":"2017-02-11T13:59:06Z","lastAt":"2017-02-11T19:50:48Z","messageCount":4,"participants":["René Scharfe","Junio C Hamano","Lars Schneider"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"311339","messageId":"7e10f934-f084-ceb4-00eb-b75cdb01886b@web.de","threadId":"45113","inReplyTo":null,"subject":"[PATCH] cocci: detect useless free(3) calls","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-02-11T13:58:44Z","receivedAt":"2017-02-11T13:59:06Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add a semantic patch for removing checks that cause free(3) to only be\ncalled with a NULL pointer, as that must be a programming mistake.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\nNo cases are found in master or next, but 1d263b93 (bisect--helper:\n`bisect_next_check` & bisect_voc shell function in C) introduced four\nof them to pu.\n\n contrib/coccinelle/free.cocci | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci\nindex e28213161a..c03ba737e5 100644\n--- a/contrib/coccinelle/free.cocci\n+++ b/contrib/coccinelle/free.cocci\n@@ -3,3 +3,9 @@ expression E;\n @@\n - if (E)\n   free(E);\n+\n+@@\n+expression E;\n+@@\n+- if (!E)\n+  free(E);\n-- \n2.11.1\n\n"},{"id":"311346","messageId":"xmqqr334h7rg.fsf@gitster.mtv.corp.google.com","threadId":"45113","inReplyTo":"7e10f934-f084-ceb4-00eb-b75cdb01886b@web.de","subject":"Re: [PATCH] cocci: detect useless free(3) calls","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-11T19:01:07Z","receivedAt":"2017-02-11T19:01:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Add a semantic patch for removing checks that cause free(3) to only be\n> called with a NULL pointer, as that must be a programming mistake.\n>\n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n> No cases are found in master or next, but 1d263b93 (bisect--helper:\n> `bisect_next_check` & bisect_voc shell function in C) introduced four\n> of them to pu.\n\nThanks.  This should have been caught by code inspection, but\nhaving automated way to do so is always good.\n\n>\n>  contrib/coccinelle/free.cocci | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci\n> index e28213161a..c03ba737e5 100644\n> --- a/contrib/coccinelle/free.cocci\n> +++ b/contrib/coccinelle/free.cocci\n> @@ -3,3 +3,9 @@ expression E;\n>  @@\n>  - if (E)\n>    free(E);\n> +\n> +@@\n> +expression E;\n> +@@\n> +- if (!E)\n> +  free(E);\n"},{"id":"311347","messageId":"5DF3AA3E-90C6-443C-A22C-489CE2C89A51@gmail.com","threadId":"45113","inReplyTo":"7e10f934-f084-ceb4-00eb-b75cdb01886b@web.de","subject":"Re: [PATCH] cocci: detect useless free(3) calls","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-02-11T19:31:15Z","receivedAt":"2017-02-11T19:31:24Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 11 Feb 2017, at 14:58, René Scharfe <l.s.r@web.de> wrote:\n> \n> Add a semantic patch for removing checks that cause free(3) to only be\n> called with a NULL pointer, as that must be a programming mistake.\n> \n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n> No cases are found in master or next, but 1d263b93 (bisect--helper:\n> `bisect_next_check` & bisect_voc shell function in C) introduced four\n> of them to pu.\n\nHi Rene,\n\nhow do you run these checks on the entire Git source?\nDo you run each semantic patch file on the source like this?\n\nspatch --sp-file contrib/coccinelle/qsort.cocci --dir /path/to/git/git\n...\nspatch --sp-file contrib/coccinelle/free.cocci --dir /path/to/git/git\n\nHow stable do you consider these checks? Would it make sense to run them\nas part of the Travis-CI build [1]? \n\nThanks,\nLars\n\n[1] https://travis-ci.org/git/git/branches"},{"id":"311348","messageId":"ca01f8de-f5ce-2201-450d-cadd6aca7cb8@web.de","threadId":"45113","inReplyTo":"5DF3AA3E-90C6-443C-A22C-489CE2C89A51@gmail.com","subject":"Re: [PATCH] cocci: detect useless free(3) calls","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-02-11T19:50:22Z","receivedAt":"2017-02-11T19:50:48Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 11.02.2017 um 20:31 schrieb Lars Schneider:\n> how do you run these checks on the entire Git source?\n> Do you run each semantic patch file on the source like this?\n> \n> spatch --sp-file contrib/coccinelle/qsort.cocci --dir /path/to/git/git\n> ...\n> spatch --sp-file contrib/coccinelle/free.cocci --dir /path/to/git/git\n\nWith \"make coccicheck\", which runs spatch against the items in the make\nvariable C_SOURCES, for all .cocci files.\n\n> How stable do you consider these checks? Would it make sense to run them\n> as part of the Travis-CI build [1]? \n\nThere seem to have been problems with older versions[2], but I'm not\naware of other issues.\n\nHaving these checks run automatically would be nice because they\nrequire a special tool which I guess not everybody is willing (or able)\nto install and because they take multiple minutes.\n\nRené\n\n\n[2] https://public-inbox.org/git/014ef44e-9dd8-40b3-a3ec-b483f938ee02@web.de/\n"}]}