Subject: Re: FREE( s, M_xxxx ) - a bug you don't want to look for!
To: David Laight <david@l8s.co.uk>
From: Jaromir Dolecek <jdolecek@netbsd.org>
List: tech-kern
Date: 06/27/2002 09:43:27
Yes, MALLOC/FREE should only be used with fixed size
argument. It should never be used with variable size argument.

Jaromir

David Laight wrote:
> 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
> 


-- 
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.NetBSD.org/Ports/i386/ps2.html
-=- We should be mindful of the potential goal, but as the tantric    -=-
-=- Buddhist masters say, ``You may notice during meditation that you -=-
-=- sometimes levitate or glow.   Do not let this distract you.''     -=-