summaryrefslogtreecommitdiff
path: root/qemu-malloc.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-02-05 22:05:49 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-02-05 22:05:49 +0000
commit8a1d02aba9f986ca03d854184cd432ee98bcd179 (patch)
tree358d40825558e8afc7e432db03e74f61750d5e17 /qemu-malloc.c
parent1fb8648d4a4e67df16fe0392590cb5ede3296387 (diff)
downloadqemu-8a1d02aba9f986ca03d854184cd432ee98bcd179.tar.gz
Terminate emulation on memory allocation failure (Avi Kivity)
Memory allocation failures are a very rare condition on virtual-memory hosts. They are also very difficult to handle correctly (especially in a hardware emulation context). Because of this, it is better to gracefully terminate emulation rather than executing untested or even unwritten recovery code paths. This patch changes the qemu memory allocation routines to terminate emulation if an allocation failure is encountered. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6526 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'qemu-malloc.c')
-rw-r--r--qemu-malloc.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/qemu-malloc.c b/qemu-malloc.c
index dc74efed17..1d00f26d00 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -22,6 +22,14 @@
* THE SOFTWARE.
*/
#include "qemu-common.h"
+#include <stdlib.h>
+
+static void *oom_check(void *ptr)
+{
+ if (ptr == NULL)
+ exit(13);
+ return ptr;
+}
void *get_mmap_addr(unsigned long size)
{
@@ -35,20 +43,18 @@ void qemu_free(void *ptr)
void *qemu_malloc(size_t size)
{
- return malloc(size);
+ return oom_check(malloc(size));
}
void *qemu_realloc(void *ptr, size_t size)
{
- return realloc(ptr, size);
+ return oom_check(realloc(ptr, size));
}
void *qemu_mallocz(size_t size)
{
void *ptr;
ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
memset(ptr, 0, size);
return ptr;
}
@@ -58,8 +64,6 @@ char *qemu_strdup(const char *str)
char *ptr;
size_t len = strlen(str);
ptr = qemu_malloc(len + 1);
- if (!ptr)
- return NULL;
memcpy(ptr, str, len + 1);
return ptr;
}