[Top][All Lists]

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (fo

From: Eric Blake
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
Date: Wed, 26 Aug 2015 06:53:05 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0

On 08/26/2015 06:02 AM, Markus Armbruster wrote:
> "Daniel P. Berrange" <address@hidden> writes:
>> The free() and g_free() functions both happily accept
>> NULL on any platform QEMU builds on.
> Do systems where free(NULL) doesn't work even exist?  Even C89
> guarantees it does nothing.

Solaris 4 was the last (pre-C89) system I am aware of that didn't like
free(NULL).  Ancient history nowadays.

> My Coccinelle semantic patch finds a few more, because it also fixes up
> the equally pointless conditional
>     if (foo) {
>         free(foo);
>         foo = NULL;
>     }

The assignment to foo is not pointless, but removing the conditional is
indeed nice.  gnulib's perl script is a lot weaker than coccinelle,
obviously :)

> @@
> expression E;
> @@
> -     if (E != NULL) {
> -         g_free(E);
> -           E = NULL;
> -     }
> +       g_free(E);
> +       E = NULL;

This only checks for g_free() before assignment to NULL; are there any
uses of raw free() that do the same?

> Result (feel free to squash it into your patch):

Whether squashed in or separate, these additional changes and the
original patch are:
Reviewed-by: Eric Blake <address@hidden>

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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