From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUaCb-0006Fg-Gd for qemu-devel@nongnu.org; Wed, 26 Aug 2015 08:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUaCY-0002kt-BL for qemu-devel@nongnu.org; Wed, 26 Aug 2015 08:53:17 -0400 References: <1440587838-25595-1-git-send-email-berrange@redhat.com> <1440587838-25595-8-git-send-email-berrange@redhat.com> <87lhcyp89e.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <55DDB6B1.2060104@redhat.com> Date: Wed, 26 Aug 2015 06:53:05 -0600 MIME-Version: 1.0 In-Reply-To: <87lhcyp89e.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="21xBKOEVquec1iSCUcHsOgoL4D4FU0gGo" Subject: Re: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , "Daniel P. Berrange" Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --21xBKOEVquec1iSCUcHsOgoL4D4FU0gGo Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/26/2015 06:02 AM, Markus Armbruster wrote: > "Daniel P. Berrange" writes: >=20 >> The free() and g_free() functions both happily accept >> NULL on any platform QEMU builds on. >=20 > 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. >=20 > My Coccinelle semantic patch finds a few more, because it also fixes up= > the equally pointless conditional >=20 > if (foo) { > free(foo); > foo =3D 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 :) >=20 > @@ > expression E; > @@ > - if (E !=3D NULL) { > - g_free(E); > - E =3D NULL; > - } > + g_free(E); > + E =3D 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): >=20 Whether squashed in or separate, these additional changes and the original patch are: Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --21xBKOEVquec1iSCUcHsOgoL4D4FU0gGo Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJV3baxAAoJEKeha0olJ0Nq7mUIALATFKayKePoaKCJ7BmLm0qV 28G6YFRHpz9BpTktp8xwv/byZRsn0X/hZIylit7ory4Fm8RdJQAugFiM+MOH1fqa 3aomPuZZrCYAGGJQPi9g21fFU6r+aAHSyrZWTDrj6MQD7Z4UYMUDhRWhO9hbAPtB ubX9FSWj5TOlCcKGEtO+3gQ8HjR7YIODpLS7LjsV1/JoJXGq89vH8lp6huw7Gmau kwyduHvIU/WnitD6BmMZORM726H/XaHiK5MHz0SBedZdLV5xul3OXom0TWzF0sVt 1rLcTM5bDssVmgC4lmnXiXDkl4ut/jyaGyWzoxAKXGnWbnVECno249SziB/PSjI= =Ln6v -----END PGP SIGNATURE----- --21xBKOEVquec1iSCUcHsOgoL4D4FU0gGo--