Received: from eggs.gnu.org ([2001:4830:134:3::10]:35778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrQa3-0004wo-7s for qemu-devel@nongnu.org; Mon, 02 Jun 2014 07:39:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrQZv-000732-OV for qemu-devel@nongnu.org; Mon, 02 Jun 2014 07:39:07 -0400 Received: from oxygen.pond.sub.org ([144.76.244.19]:46394) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrQZv-00072k-IN for qemu-devel@nongnu.org; Mon, 02 Jun 2014 07:38:59 -0400 From: Markus Armbruster References: <1401480140-18653-1-git-send-email-ehabkost@redhat.com> <1401480140-18653-2-git-send-email-ehabkost@redhat.com> Date: Mon, 02 Jun 2014 13:38:52 +0200 In-Reply-To: <1401480140-18653-2-git-send-email-ehabkost@redhat.com> (Eduardo Habkost's message of "Fri, 30 May 2014 17:02:18 -0300") Message-ID: <87wqcz4k37.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain 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: Eduardo Habkost Cc: Marcel Apfelbaum , Luiz Capitulino , qemu-devel@nongnu.org, Anthony Liguori , Andreas =?utf-8?Q?F=C3=A4rber?= 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);