On Sun, Dec 17, 2000 at 03:17:35PM -0600, Chris Costello wrote:
>    2.  The C standard dictates that free() does nothing when it
> gets a NULL argument.  

Well, it dictates that free(NULL) is safe -- it doesn't dictate that 
it ``does nothing''.  Which brings me to my next comment:

> The other two are just extra clutter.

I suspect that the programmer writing 

    if (data)
            free(data);

is motivated by the wish to avoid the function call overhead if you
already know darn well that there is nothing to free.  In the
multithreaded case, there is probably some locking going on, too.

I don't blame authors of storage allocation code if they do not write
free like this:

    void
    free(void *p)
    {
            if (p == NULL)
                    return;
        .
        .
        .


It would be silly to optimize for freeing NULL pointers.
-- 
Jacques Vidrine / [EMAIL PROTECTED] / [EMAIL PROTECTED] / [EMAIL PROTECTED]


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to