public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jim Meyering <jim@meyering.net>
Cc: Janne Blomqvist <blomqvist.janne@gmail.com>,
	       "Joseph S. Myers" <joseph@codesourcery.com>,
	gcc-patches@gcc.gnu.org,        java-patches@gcc.gnu.org,
	fortran@gcc.gnu.org
Subject: Re: [PATCH gcc/fortran] get rid of gfc_free
Date: Tue, 15 Mar 2011 10:08:00 -0000	[thread overview]
Message-ID: <20110315100826.GV30899@tyan-ft48-01.lab.bos.redhat.com> (raw)
In-Reply-To: <87zkow3dmp.fsf_-_@rho.meyering.net>

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);

	Jakub

  reply	other threads:[~2011-03-15 10:08 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87zkp9zmq0.fsf@rho.meyering.net>
2011-03-05 19:16 ` avoid useless if-before-free tests Joseph S. Myers
2011-03-07 19:52   ` Dr Andrew John Hughes
2011-03-07 22:47     ` Joseph S. Myers
2011-03-08 16:57       ` Dr Andrew John Hughes
2011-03-08 17:07         ` Andrew Haley
2011-03-08 17:17         ` Jim Meyering
2011-03-08 10:45   ` Jim Meyering
2011-03-08 14:21   ` [PATCH v2] " Jim Meyering
2011-03-08 14:30     ` Rainer Orth
2011-03-08 15:28       ` Ian Lance Taylor
2011-03-08 15:36         ` Jakub Jelinek
2011-03-08 17:03       ` Jim Meyering
2011-03-08 18:45         ` Rainer Orth
2011-03-08 19:13           ` Jim Meyering
2011-03-08 19:20             ` Rainer Orth
2011-03-08 19:39               ` Jakub Jelinek
2011-03-08 17:54     ` [PATCH v3] " Jim Meyering
2011-03-08 19:34       ` DJ Delorie
2011-03-15  9:19       ` Janne Blomqvist
2011-03-15 10:03         ` [PATCH gcc/fortran] get rid of gfc_free Jim Meyering
2011-03-15 10:08           ` Jakub Jelinek [this message]
2011-03-15 10:27             ` Jim Meyering
2011-03-15 14:18           ` Janne Blomqvist
2011-03-15 18:21             ` Jim Meyering
2011-03-24 16:51         ` [PATCH v3] Re: avoid useless if-before-free tests Jim Meyering
2011-04-15  7:26           ` Janne Blomqvist
2011-04-15  7:54             ` Jim Meyering
2011-04-15  8:20               ` Janne Blomqvist
2011-04-15  8:23                 ` Jim Meyering
2011-04-15 13:20                 ` Tom Tromey
2011-04-15 17:52                   ` Jim Meyering

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=20110315100826.GV30899@tyan-ft48-01.lab.bos.redhat.com \
    --to=jakub@redhat.com \
    --cc=blomqvist.janne@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=java-patches@gcc.gnu.org \
    --cc=jim@meyering.net \
    --cc=joseph@codesourcery.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).