freemyipod r570 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r569‎ | r570 | r571 >
Date:00:04, 8 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Prevent a null pointer dereference if realloc hits an out of memory condition
Modified paths:
  • /emcore/trunk/malloc.c (modified) (history)

Diff [purge]

Index: emcore/trunk/malloc.c
@@ -59,8 +59,11 @@
6060 size_t oldsize = tlsf_block_size(ptr);
6161 struct scheduler_thread* owner = *((struct scheduler_thread**)(ptr + size - 4));
6262 ptr = tlsf_realloc(global_mallocpool, ptr, size + 4);
63 - size = tlsf_block_size(ptr);
64 - *((struct scheduler_thread**)(ptr + size - 4)) = owner;
 63+ if (ptr)
 64+ {
 65+ size = tlsf_block_size(ptr);
 66+ *((struct scheduler_thread**)(ptr + size - 4)) = owner;
 67+ }
6568 mutex_unlock(&malloc_mutex);
6669 return ptr;
6770 }