Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Dec 2000 15:31:29 -0600
From:      "Jacques A. Vidrine" <n@nectar.com>
To:        Chris Costello <chris@calldei.com>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Why not another style thread? (was Re: cvs commit: src/lib/libc/gen getgrent.c)
Message-ID:  <20001217153129.B63080@hamlet.nectar.com>
In-Reply-To: <20001217151735.D54486@holly.calldei.com>; from chris@calldei.com on Sun, Dec 17, 2000 at 03:17:35PM -0600
References:  <200012172110.eBHLAfU46563@freefall.freebsd.org> <20001217151509.A63051@hamlet.nectar.com> <20001217151735.D54486@holly.calldei.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001217153129.B63080>