summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/cygheap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r--winsup/cygwin/cygheap.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 157c7e478..09bd680bf 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -111,13 +111,18 @@ _cfree (void *ptr)
static void *__stdcall
_crealloc (void *ptr, int size)
{
- char *newptr;
- int oldsize = bucket2size[*(int *) ((char *) ptr - 4)];
- if (size <= oldsize)
- return ptr;
- newptr = (char *) _cmalloc (size);
- memcpy (newptr, ptr, oldsize);
- _cfree (ptr);
+ void *newptr;
+ if (ptr == NULL)
+ newptr = _cmalloc (size);
+ else
+ {
+ int oldsize = bucket2size[*(int *) ((char *) ptr - 4)];
+ if (size <= oldsize)
+ return ptr;
+ newptr = _cmalloc (size);
+ memcpy (newptr, ptr, oldsize);
+ _cfree (ptr);
+ }
return newptr;
}