Subject: FREE( s, M_xxxx ) - a bug you don't want to look for!
To: None <tech-kern@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: tech-kern
Date: 06/26/2002 22:07:50
I accidentally wrote:
	FREE( s, M_tag )
when hacking some kernel code - just cloning some other calls.

What I didn't expect until after 2 days of debuging the mess
that resulted - process 1 (init) proc area was being overwritten
by 0 .. 7 by (I think) amap_copy() - was that FREE() isn't just
a wrapper for free() but an inline of it [1].

Unfortunately the inlined code contains 'int s = splxxx();'
which causes serious grief when 's' is also a macro argument.

Two things:
1) Why isn't the kernel compiled with -Wshadow
2) Why doesn't the #define use safer names
   (s is quite likely to be holding a different PL level!)

	David

[1] Has anyone checked the performance with/without malloc
and free inlined?  They look a bit big to me!
The only benefit is if malloc has a fixed size - when the
compile does the 'power of 2' calculation for you, but
many processors have a 'find first bit' instruction
or a lookup table can be used.

-- 
David Laight: david@l8s.co.uk