Eduardo Habkost <ehabk...@redhat.com> writes: > g_free() is NULL-safe. > > Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> > --- > Cc: Anthony Liguori <aligu...@amazon.com> > Cc: Luiz Capitulino <lcapitul...@redhat.com> > --- > 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 <arm...@redhat.com> 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);