aboutsummaryrefslogtreecommitdiff
path: root/osdep.c
diff options
context:
space:
mode:
authormalc <av1474@comtv.ru>2009-07-08 18:24:05 +0400
committermalc <av1474@comtv.ru>2009-07-08 18:24:05 +0400
commitd644f8beaa268a4e36b473f283f0b5a5ff66d8c2 (patch)
treed7ba6ca3b2bb598a84241495484db89cc8ea01c5 /osdep.c
parente8d2a88755b849bdadaf80d19e342eade3c017bc (diff)
downloadqemu-d644f8beaa268a4e36b473f283f0b5a5ff66d8c2.zip
qemu-d644f8beaa268a4e36b473f283f0b5a5ff66d8c2.tar.gz
qemu-d644f8beaa268a4e36b473f283f0b5a5ff66d8c2.tar.bz2
Add out of memory and zero size argument checks to be consistent with
the qemu_malloc routines
Diffstat (limited to 'osdep.c')
-rw-r--r--osdep.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/osdep.c b/osdep.c
index b300ba1..410e436 100644
--- a/osdep.c
+++ b/osdep.c
@@ -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
}