diff options
author | malc <av1474@comtv.ru> | 2009-07-08 18:24:05 +0400 |
---|---|---|
committer | malc <av1474@comtv.ru> | 2009-07-08 18:24:05 +0400 |
commit | d644f8beaa268a4e36b473f283f0b5a5ff66d8c2 (patch) | |
tree | d7ba6ca3b2bb598a84241495484db89cc8ea01c5 | |
parent | e8d2a88755b849bdadaf80d19e342eade3c017bc (diff) |
Add out of memory and zero size argument checks to be consistent with
the qemu_malloc routines
-rw-r--r-- | osdep.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -51,10 +51,23 @@ #include "sysemu.h" #include "qemu_socket.h" +#if !defined(_POSIX_C_SOURCE) || defined(_WIN32) +static void *oom_check(void *ptr) +{ + if (ptr == NULL) { + abort(); + } + return ptr; +} +#endif + #if defined(_WIN32) void *qemu_memalign(size_t alignment, size_t size) { - return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); + if (!size) { + abort(); + } + return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); } void *qemu_vmalloc(size_t size) @@ -62,7 +75,10 @@ void *qemu_vmalloc(size_t size) /* FIXME: this is not exactly optimal solution since VirtualAlloc has 64Kb granularity, but at least it guarantees us that the memory is page aligned. */ - return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); + if (!size) { + abort(); + } + return oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)); } void qemu_vfree(void *ptr) @@ -106,6 +122,10 @@ static void *kqemu_vmalloc(size_t size) struct statfs stfs; #endif + if (!size) { + abort (); + } + if (phys_ram_fd < 0) { tmpdir = getenv("QEMU_TMPDIR"); if (!tmpdir) @@ -188,12 +208,12 @@ void *qemu_memalign(size_t alignment, size_t size) void *ptr; ret = posix_memalign(&ptr, alignment, size); if (ret != 0) - return NULL; + abort(); return ptr; #elif defined(HOST_BSD) - return valloc(size); + return oom_check(valloc(size)); #else - return memalign(alignment, size); + return oom_check(memalign(alignment, size)); #endif } |