This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [patch] Cleanup: don't call free(NULL) unnecessarily
- From: Roland McGrath <roland at hack dot frob dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: Paul Pluzhnikov <ppluzhnikov at google dot com>, libc-alpha at sourceware dot org, ahh at google dot com
- Date: Mon, 11 Mar 2013 09:55:30 -0700 (PDT)
- Subject: Re: [patch] Cleanup: don't call free(NULL) unnecessarily
- References: <ye6qehft7j12.fsf@elbrus2.mtv.corp.google.com><5136651F.6090202@redhat.com>
Since free (NULL) is thoroughly well-specified as a no-op, it never
qualifies as a "cleanup" to add code to avoid it. If anything, it's an
optimization. Like all claims of optimization, it needs exploration of
the trade-offs involved and justification for the change.
It was past policy never to add tests before free calls. The rationale
for that is that free (NULL) is cheap enough as a no-op and the cases
where it would actually be called are not in hot paths. If they're not
hot paths, then there is no justification for an optimization change.
In fact, adding any instructions at all is should always be presumed to
be a pessimization due to general I-cache pressure. So adding a test
must be justified on a specific performance-analysis basis as an
optimization, and weighed against the maintenance burden of making the
source code larger and more complex.
Thanks,
Roland