On 11/23/2010 09:12 AM, Hannes Reinecke wrote:
qemu-malloc.c has:
void qemu_free(void *ptr)
{
trace_qemu_free(ptr);
free(ptr);
}
and 'free' doesn't normally do an error checking on the argument.
Am I missing something?
It's not error checking: from free(3),
free() frees the memory space pointed to by ptr, which must have been
returned by a previous call to malloc(), calloc() or realloc().
Otherwise, or if free(ptr) has already been called before, undefined
behavior occurs. If ptr is NULL, no operation is performed.
Which means, that unless ptr is so often NULL that there is a measurable
overhead from the call (unlikely in any case, not just this one) the
"if" is actually going to be done by "free", and thus causing actually
worse performance.
Not that man pages are always right, but in this case they agree with
POSIX. :)
Paolo