[PATCH] xkb: when copying the keymap, make sure the structs default to 0/NULL.

Alan Coopersmith alan.coopersmith at sun.com
Thu Feb 7 08:38:17 PST 2008


Eric Piel wrote:
> Rene van Paassen wrote:
>> On 07/02/2008, Daniel Stone <daniel at fooishbar.org> wrote:
> :
>>> for consistency.
>>>
>>>>               if (dst->geom->sz_key_aliases && dst->geom->key_aliases) {
>>>>                   xfree(dst->geom->key_aliases);
>>>> -                dst->geom->key_aliases = NULL;
>>>>               }
>> are the xfree semantics different from the malloc/free semantics? free
>> should not trip over a NULL pointer. So we should NOT test for
>> dst->geom->key_aliases (etc.) to be non-NULL before freeing these
>> pointers.
>>
>> free(NULL); is perfectly valid.
> A priori, that should be obvious, but "man XFree" and you get a scary 
> info ;-)
> [..]  A NULL pointer cannot be passed to this function. [..]
> 
> I gues the semantic of xfree() is the same...

Well, there's XFree(), Xfree(), and xfree(), and they're different on
the client and the server sides of the code.   Many kittens died to
bring us this implementation.

Mostly, they just reduce down to free() from libc, which has to take
a NULL if it's ANSI/ISO-C89-compliant, though the server-side
implementation throws in an extra NULL check just to be sure:

xserver/include/os.h: #define xfree(ptr) Xfree((pointer)(ptr))

xserver/os/utils.c:

_X_EXPORT void
Xfree(pointer ptr)
{
     if (ptr)
         free((char *)ptr);
}



-- 
	-Alan Coopersmith-           alan.coopersmith at sun.com
	 Sun Microsystems, Inc. - X Window System Engineering



More information about the xorg mailing list