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

Peter Hutterer mailinglists at who-t.net
Thu Feb 7 01:59:48 PST 2008


Rene van Paassen wrote:
> 
> 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.

This is a misunderstanding. The problem in the code was that XKB's 
tendency to do the following.


struct *foo = xalloc(just the right size);
foo->num_bar = 0;

// blah blah

if (foo->num_bar)
{
	// happy happy picnic
}
xfree(foo->bar); // Yay! Nirvana! Finally!


xfree doesn't mind NULL. It's these "not quite NULL but not yet a memory 
address either" values that make it burp.

Cheers,
   Peter



More information about the xorg mailing list