Fix qemu_malloc.
authormalc <malc@c046a42c-6fe2-441c-8c8c-71466251a162>
Wed, 28 Jan 2009 17:16:56 +0000 (17:16 +0000)
committermalc <malc@c046a42c-6fe2-441c-8c8c-71466251a162>
Wed, 28 Jan 2009 17:16:56 +0000 (17:16 +0000)
make {linux,bsd}-user qemu_realloc handle ptr == NULL correctly.
spotted by malc.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6466 c046a42c-6fe2-441c-8c8c-71466251a162

bsd-user/mmap.c
linux-user/mmap.c

index 66233ab..e916a65 100644 (file)
@@ -127,6 +127,8 @@ void *qemu_realloc(void *ptr, size_t size)
     size_t old_size, copy;
     void *new_ptr;
 
+    if (!ptr)
+        return qemu_malloc(size);
     old_size = *(size_t *)((char *)ptr - 16);
     copy = old_size < size ? old_size : size;
     new_ptr = qemu_malloc(size);
index d0fc3e3..888b491 100644 (file)
@@ -128,6 +128,8 @@ void *qemu_realloc(void *ptr, size_t size)
     size_t old_size, copy;
     void *new_ptr;
 
+    if (!ptr)
+        return qemu_malloc(size);
     old_size = *(size_t *)((char *)ptr - 16);
     copy = old_size < size ? old_size : size;
     new_ptr = qemu_malloc(size);