Behaviour change for double-free'ing a pointer
Tim Cussins
timcussins at eml.cc
Wed Dec 19 15:58:02 UTC 2007
Hi Joel
On Nov 26th there was a commit that changed the behaviour of free() when
attempting to free a previously free'd pointer. Before the change, the
behaviour was to assert(0) - the new behaviour is to printk() a warning
and continue.
void free(
void *ptr
)
{
...
if ( !_Protected_heap_Free( &RTEMS_Malloc_Heap, ptr ) ) {
printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
ptr,
RTEMS_Malloc_Heap.start,
RTEMS_Malloc_Heap.end
);
}
IMHO the assert method is more correct, as an obvious programmer error
has been detected and can be caught and a debugger may be attached or
whatnot.
I guess there's a good argument for tolerating a double-free - primarily
that the second free is unlikely to cause disasterous software
behaviour. Contrast this with assert(), which is undeniably a total
disaster from a user perspective... :P
Perhaps the choice of behaviour could be based on RTEMS_HEAP_DEBUG?
Regards,
Tim
More information about the users
mailing list