[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
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-trivial] [Qemu-devel] [PATCH 1/7] maint: remove double semicolons in many files, (continued)
- [Qemu-trivial] [PATCH 3/7] maint: remove unused include for assert.h, Daniel P. Berrange, 2015/08/26
- [Qemu-trivial] [PATCH 4/7] maint: remove unused include for dirent.h, Daniel P. Berrange, 2015/08/26
- [Qemu-trivial] [PATCH 5/7] maint: remove unused include for signal.h, Daniel P. Berrange, 2015/08/26
- [Qemu-trivial] [PATCH 6/7] maint: remove unused include for strings.h, Daniel P. Berrange, 2015/08/26
- [Qemu-trivial] [PATCH 2/7] maint: remove / fix many doubled words, Daniel P. Berrange, 2015/08/26
- [Qemu-trivial] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern, Daniel P. Berrange, 2015/08/26
- Re: [Qemu-trivial] [Qemu-devel] [PATCH 0/7] Misc trivial code cleanups, Markus Armbruster, 2015/08/26