From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28874 invoked by alias); 15 Mar 2011 10:27:18 -0000 Received: (qmail 28848 invoked by uid 22791); 15 Mar 2011 10:27:17 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,SARE_SUB_GETRID,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx.meyering.net (HELO mx.meyering.net) (82.230.74.64) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Mar 2011 10:27:11 +0000 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 469B2600B4; Tue, 15 Mar 2011 11:27:09 +0100 (CET) From: Jim Meyering To: Jakub Jelinek Cc: Janne Blomqvist , "Joseph S. Myers" , gcc-patches@gcc.gnu.org, java-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: Re: [PATCH gcc/fortran] get rid of gfc_free In-Reply-To: <20110315100826.GV30899@tyan-ft48-01.lab.bos.redhat.com> (Jakub Jelinek's message of "Tue, 15 Mar 2011 11:08:26 +0100") References: <87zkp9zmq0.fsf@rho.meyering.net> <877hc9r8w6.fsf_-_@rho.meyering.net> <877hc9pkhp.fsf_-_@rho.meyering.net> <87zkow3dmp.fsf_-_@rho.meyering.net> <20110315100826.GV30899@tyan-ft48-01.lab.bos.redhat.com> Date: Tue, 15 Mar 2011 10:27:00 -0000 Message-ID: <87tyf43chu.fsf@rho.meyering.net> MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg00812.txt.bz2 Jakub Jelinek wrote: > On Tue, Mar 15, 2011 at 11:02:38AM +0100, Jim Meyering wrote: >> > Instead of "please let us know", maybe recommend using >> > __builtin_expect instead? E.g. something like >> > >> > if (__builtin_expect (ptr != NULL, 0)) >> > free (ptr); >> >> Good idea. Thanks. >> Though how about avoiding the double negative? >> >> if (__builtin_expect (ptr == NULL, 1)) >> free (ptr); > > What double negative? if (__builtin_expect (ptr != NULL, 0)) free (ptr); > is certainly correct, the latter is wrong, it will leak memory. > It will call free only if ptr is NULL, i.e. do a useless free (NULL), > if it is non-NULL, it will not do anything. > You could do > if (!__builtin_expect (ptr == NULL, 1)) > free (ptr); > but that doesn't seem to be nicer or clearer than > if (__builtin_expect (ptr != NULL, 0)) > free (ptr); Thanks for the quick correction. I've fixed it locally, too.