Re: [PATCH] gdb: remove unnecessary NULL checks before xfree

Pedro Alves
2020-05-21T16:59:22Z

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

Thanks,
Pedro Alves