Merge pull request #29 from shinyquagsire23/realloc

Realloc should only return the allocated pointer if it is passed a nullptr to rellocate
This commit is contained in:
Brett Lawson 2016-08-05 14:51:12 -07:00 committed by GitHub
commit b41ae7993c

View File

@ -20,15 +20,30 @@ __wrap_free(void *ptr) {
} }
} }
size_t
__wrap_malloc_usable_size(void *ptr) {
return MEMGetSizeForMBlockExpHeap(ptr);
}
void * void *
__wrap_realloc(void *ptr, size_t size) { __wrap_realloc(void *ptr, size_t size) {
if (!ptr) {
return __wrap_malloc(size);
}
if (__wrap_malloc_usable_size(ptr) >= size) {
return ptr;
}
void *realloc_ptr = __wrap_malloc(size); void *realloc_ptr = __wrap_malloc(size);
if(realloc_ptr) { if(!realloc_ptr) {
memcpy(realloc_ptr, ptr, size); return NULL;
__wrap_free(ptr);
} }
memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr));
__wrap_free(ptr);
return realloc_ptr; return realloc_ptr;
} }
@ -43,11 +58,6 @@ __wrap_calloc(size_t num, size_t size) {
return ptr; return ptr;
} }
size_t
__wrap_malloc_usable_size(void *ptr) {
return MEMGetSizeForMBlockExpHeap(ptr);
}
void * void *
__wrap_valloc(size_t size) { __wrap_valloc(size_t size) {
return __wrap_memalign(64, size); return __wrap_memalign(64, size);