Commit a7d27b536ffc0773028a90f14580552c0c3ddb2a
1 parent
20094efc
Abort on attempts to allocate zero bytes
http://marc.info/?t=124267873300015&r=1&w=2 Signed-off-by: malc <av1474@comtv.ru>
Showing
1 changed file
with
7 additions
and
2 deletions
qemu-malloc.c
@@ -43,6 +43,8 @@ void qemu_free(void *ptr) | @@ -43,6 +43,8 @@ void qemu_free(void *ptr) | ||
43 | 43 | ||
44 | void *qemu_malloc(size_t size) | 44 | void *qemu_malloc(size_t size) |
45 | { | 45 | { |
46 | + if (!size) | ||
47 | + abort(); | ||
46 | return oom_check(malloc(size)); | 48 | return oom_check(malloc(size)); |
47 | } | 49 | } |
48 | 50 | ||
@@ -50,8 +52,11 @@ void *qemu_realloc(void *ptr, size_t size) | @@ -50,8 +52,11 @@ void *qemu_realloc(void *ptr, size_t size) | ||
50 | { | 52 | { |
51 | if (size) | 53 | if (size) |
52 | return oom_check(realloc(ptr, size)); | 54 | return oom_check(realloc(ptr, size)); |
53 | - else | ||
54 | - return realloc(ptr, size); | 55 | + else { |
56 | + if (ptr) | ||
57 | + return realloc(ptr, size); | ||
58 | + } | ||
59 | + abort(); | ||
55 | } | 60 | } |
56 | 61 | ||
57 | void *qemu_mallocz(size_t size) | 62 | void *qemu_mallocz(size_t size) |