From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFDJm-0006B3-9k for qemu-devel@nongnu.org; Wed, 06 Aug 2014 22:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFDJc-0000Fz-St for qemu-devel@nongnu.org; Wed, 06 Aug 2014 22:20:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFDJc-0000Fc-LG for qemu-devel@nongnu.org; Wed, 06 Aug 2014 22:20:28 -0400 Date: Thu, 7 Aug 2014 10:19:21 +0800 From: Amos Kong Message-ID: <20140807021921.GA8109@z.redhat.com> References: <1401480140-18653-1-git-send-email-ehabkost@redhat.com> <1401480140-18653-2-git-send-email-ehabkost@redhat.com> <87wqcz4k37.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wqcz4k37.fsf@blackfin.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Eduardo Habkost , Marcel Apfelbaum , qemu-devel@nongnu.org, Luiz Capitulino , Anthony Liguori , Andreas =?iso-8859-1?Q?F=E4rber?= On Mon, Jun 02, 2014 at 01:38:52PM +0200, Markus Armbruster wrote: > Eduardo Habkost writes: > > > g_free() is NULL-safe. > > > > Signed-off-by: Eduardo Habkost > > --- > > Cc: Anthony Liguori > > Cc: Luiz Capitulino > > --- > > backends/rng-random.c | 5 +---- > > 1 file changed, 1 insertion(+), 4 deletions(-) > > > > diff --git a/backends/rng-random.c b/backends/rng-random.c > > index 136499d..601d9dc 100644 > > --- a/backends/rng-random.c > > +++ b/backends/rng-random.c > > @@ -106,10 +106,7 @@ static void rng_random_set_filename(Object *obj, const char *filename, > > return; > > } > > > > - if (s->filename) { > > - g_free(s->filename); > > - } > > - > > + g_free(s->filename); > > s->filename = g_strdup(filename); > > } > > Reviewed-by: Markus Armbruster > > > Note there are a quite a few more instances of this anti-pattern. > Coccinelle can find them, semantic patch appended. Beware, it can throw > away comments in the conditional, which is usually not what we want. > > > @@ > expression E; > @@ > - if (E != NULL) { > - g_free(E); > - } > + g_free(E); [amos@z qemu]$ grep g_free -B 2 -r * |less then try to search "/if.*NULL" Not all can be found by this way, but many instances are found. -- Amos.