Skip to content

Commit

Permalink
[malloc] Report caller address as soon as memory corruption is detected
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Dec 15, 2014
1 parent 7871666 commit 35c5379
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/core/malloc.c
Expand Up @@ -517,6 +517,10 @@ void * realloc ( void *old_ptr, size_t new_size ) {
VALGRIND_FREELIKE_BLOCK ( old_ptr, 0 );
}

if ( ASSERTED ) {
DBGC ( &heap, "Possible memory corruption detected from %p\n",
__builtin_return_address ( 0 ) );
}
return new_ptr;
}

Expand All @@ -530,7 +534,14 @@ void * realloc ( void *old_ptr, size_t new_size ) {
* will be aligned to at least a multiple of sizeof(void*).
*/
void * malloc ( size_t size ) {
return realloc ( NULL, size );
void *ptr;

ptr = realloc ( NULL, size );
if ( ASSERTED ) {
DBGC ( &heap, "Possible memory corruption detected from %p\n",
__builtin_return_address ( 0 ) );
}
return ptr;
}

/**
Expand All @@ -544,7 +555,12 @@ void * malloc ( size_t size ) {
* If @c ptr is NULL, no action is taken.
*/
void free ( void *ptr ) {

realloc ( ptr, 0 );
if ( ASSERTED ) {
DBGC ( &heap, "Possible memory corruption detected from %p\n",
__builtin_return_address ( 0 ) );
}
}

/**
Expand All @@ -564,6 +580,10 @@ void * zalloc ( size_t size ) {
data = malloc ( size );
if ( data )
memset ( data, 0, size );
if ( ASSERTED ) {
DBGC ( &heap, "Possible memory corruption detected from %p\n",
__builtin_return_address ( 0 ) );
}
return data;
}

Expand Down

0 comments on commit 35c5379

Please sign in to comment.