diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 66233abc11..e916a6544e 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -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); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index d0fc3e3d1a..888b491403 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -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);