[PATCH] gdb: remove unnecessary NULL checks before xfree

Simon Marchi simark@simark.ca
Thu May 21 17:11:46 GMT 2020


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


More information about the Gdb-patches mailing list