summaryrefslogtreecommitdiff
path: root/qemu-malloc.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2009-12-09 12:59:36 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2009-12-12 07:59:37 -0600
commit20ff6c8066eb5346b9e066851cf8a1e0564a0f1a (patch)
treea8a990d78768ed038cdbf518aa7baf9e063e05f9 /qemu-malloc.c
parent725b8a6983215de4e510be68d120279d29ceec41 (diff)
downloadqemu-20ff6c8066eb5346b9e066851cf8a1e0564a0f1a.tar.gz
qemu-20ff6c8066eb5346b9e066851cf8a1e0564a0f1a.tar.bz2
qemu-20ff6c8066eb5346b9e066851cf8a1e0564a0f1a.zip
Do not abort on qemu_malloc(0) in production builds
qemu_malloc() does not allow size=0 to be passed in and aborts on this behavior. Unfortunately, there is good reason to believe that within qemu, there are a number of, so far, undetected places that assume size=0 can be safely passed. Since we do not want to abort unnecessarily in production builds, return qemu_malloc(1) whenever the version file indicates that this is a production build. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-malloc.c')
-rw-r--r--qemu-malloc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/qemu-malloc.c b/qemu-malloc.c
index 295d1856ef..5d9e34d69d 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -42,22 +42,29 @@ void qemu_free(void *ptr)
free(ptr);
}
+static int allow_zero_malloc(void)
+{
+#if defined(CONFIG_ZERO_MALLOC)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
void *qemu_malloc(size_t size)
{
- if (!size) {
+ if (!size && !allow_zero_malloc()) {
abort();
}
- return oom_check(malloc(size));
+ return oom_check(malloc(size ? size : 1));
}
void *qemu_realloc(void *ptr, size_t size)
{
if (size) {
return oom_check(realloc(ptr, size));
- } else {
- if (ptr) {
- return realloc(ptr, size);
- }
+ } else if (allow_zero_malloc()) {
+ return oom_check(realloc(ptr, size ? size : 1));
}
abort();
}