From 1289745bf8697d7bf6aa4031b3670246ac598af9 Mon Sep 17 00:00:00 2001 From: Andrew Munger Date: Thu, 28 Jun 2007 07:05:24 +0000 Subject: [PATCH] Fix realloc behavior when size == 0 and ptr != NULL. Patch by DrV, bug 2347. svn path=/trunk/; revision=27299 --- reactos/lib/sdk/crt/stdlib/malloc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/reactos/lib/sdk/crt/stdlib/malloc.c b/reactos/lib/sdk/crt/stdlib/malloc.c index 4273c5a53c8..9498f330df4 100644 --- a/reactos/lib/sdk/crt/stdlib/malloc.c +++ b/reactos/lib/sdk/crt/stdlib/malloc.c @@ -72,19 +72,23 @@ void* calloc(size_t _nmemb, size_t _size) void* realloc(void* _ptr, size_t _size) { size_t nSize; - - if (( _size == 0) && (_ptr !=NULL)) + + if (_ptr == NULL) + return malloc(_size); + + if (_size == 0) + { + free(_ptr); return NULL; + } nSize = ROUND_SIZE(_size); + /* check for integer overflow */ if (nSize<_size) return NULL; - - if (!_ptr) return malloc(_size); - if (_size) return HeapReAlloc(hHeap, 0, _ptr, nSize); - free(_ptr); - return NULL; + + return HeapReAlloc(hHeap, 0, _ptr, nSize); } /*