qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 1/3] rng-random: NULL check not needed before g_free()
Date: Mon, 02 Jun 2014 13:38:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Eduardo Habkost <address@hidden> writes:

> g_free() is NULL-safe.
>
> Signed-off-by: Eduardo Habkost <address@hidden>
> ---
> Cc: Anthony Liguori <address@hidden>
> Cc: Luiz Capitulino <address@hidden>
> ---
>  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 <address@hidden>


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]