summaryrefslogtreecommitdiffstats
path: root/src/core/malloc.c
diff options
context:
space:
mode:
authorMichael Brown2014-12-15 15:48:02 +0100
committerMichael Brown2014-12-15 15:48:02 +0100
commit35c5379760aa1fea5e38f7a78b090f92bb7813ee (patch)
tree4a826ddbcd87e5eac90baa2e7d7daa3d5b9a59e6 /src/core/malloc.c
parent[malloc] Check integrity of free list (diff)
downloadipxe-35c5379760aa1fea5e38f7a78b090f92bb7813ee.tar.gz
ipxe-35c5379760aa1fea5e38f7a78b090f92bb7813ee.tar.xz
ipxe-35c5379760aa1fea5e38f7a78b090f92bb7813ee.zip
[malloc] Report caller address as soon as memory corruption is detected
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/malloc.c')
-rw-r--r--src/core/malloc.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/core/malloc.c b/src/core/malloc.c
index cd925e7c..d9c07495 100644
--- a/src/core/malloc.c
+++ b/src/core/malloc.c
@@ -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;
}
@@ -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;
}
/**
@@ -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 ) );
+ }
}
/**
@@ -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;
}