Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Pedro Alves <palves@redhat.com>,
	Simon Marchi <simon.marchi@efficios.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: remove unnecessary NULL checks before xfree
Date: Thu, 21 May 2020 13:11:46 -0400	[thread overview]
Message-ID: <d35c1bf2-b3b5-9e93-6994-53f538f9b561@simark.ca> (raw)
In-Reply-To: <9267cb3e-36ae-5d05-d636-37ef2d177190@redhat.com>

On 2020-05-21 12:59 p.m., Pedro Alves via Gdb-patches wrote:
> On 5/21/20 4:10 PM, Simon Marchi via Gdb-patches wrote:
>> I was inspired by a series of patches merged by Alan Modra in the other
>> projects, so I did the same in GDB with a bit of Coccinelle and grep.
>>
>> This patch removes the unnecessary NULL checks before calls to xfree.
>> They are unnecessary because xfree already does a NULL check.  Since
>> free is supposed to handle NULL values correctly, the NULL check in
>> xfree itself is also questionable, but I've left it there for now.
> 
> xfree was invented exactly because some ancient hosts did not handle
> free(NULL) gracefully:
> 
>   https://sourceware.org/legacy-ml/gdb/2000-11/msg00276.html
> 
> I'd like to believe that such hosts are long gone.
> 
> (It's a reasonable micro-optimization to check for NULL
> before calling free, to avoid the function call overhead,
> but I don't think this is the motivation for any of the
> cases here.  Since xfree is inline, I guess we're applying
> that micro-optimization everywhere, by chance.)

I'm fine leaving it in xfree for that reason, it doesn't really hurt.

Simon


      reply	other threads:[~2020-05-21 17:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 15:10 Simon Marchi
2020-05-21 15:23 ` Tom Tromey
2020-05-21 17:12   ` Simon Marchi
2020-05-21 16:59 ` Pedro Alves
2020-05-21 17:11   ` Simon Marchi [this message]

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=d35c1bf2-b3b5-9e93-6994-53f538f9b561@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=simon.marchi@efficios.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