From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
Date: Wed, 26 Aug 2015 06:53:05 -0600 [thread overview]
Message-ID: <55DDB6B1.2060104@redhat.com> (raw)
In-Reply-To: <87lhcyp89e.fsf@blackfin.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 1342 bytes --]
On 08/26/2015 06:02 AM, Markus Armbruster wrote:
> "Daniel P. Berrange" <berrange@redhat.com> 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 <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-08-26 12:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-26 11:17 [Qemu-devel] [PATCH 0/7] Misc trivial code cleanups Daniel P. Berrange
2015-08-26 11:17 ` [Qemu-devel] [PATCH 1/7] maint: remove double semicolons in many files Daniel P. Berrange
2015-08-26 11:29 ` Marc-André Lureau
2015-08-26 11:17 ` [Qemu-devel] [PATCH 2/7] maint: remove / fix many doubled words Daniel P. Berrange
2015-08-26 11:31 ` Marc-André Lureau
2015-08-26 11:17 ` [Qemu-devel] [PATCH 3/7] maint: remove unused include for assert.h Daniel P. Berrange
2015-08-26 11:17 ` [Qemu-devel] [PATCH 4/7] maint: remove unused include for dirent.h Daniel P. Berrange
2015-08-26 11:17 ` [Qemu-devel] [PATCH 5/7] maint: remove unused include for signal.h Daniel P. Berrange
2015-08-26 11:17 ` [Qemu-devel] [PATCH 6/7] maint: remove unused include for strings.h Daniel P. Berrange
2015-08-26 11:17 ` [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern Daniel P. Berrange
2015-08-26 11:36 ` Marc-André Lureau
2015-08-26 12:02 ` Markus Armbruster
2015-08-26 12:53 ` Eric Blake [this message]
2015-08-26 16:09 ` Markus Armbruster
2015-08-26 12:03 ` [Qemu-devel] [PATCH 0/7] Misc trivial code cleanups Markus Armbruster
2015-09-06 10:51 ` Michael Tokarev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55DDB6B1.2060104@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).