fix qemu_malloc(0)
PATCH 1/1 fix qemu_malloc(0)
Don't abort. Return malloc(1) instead as suggested by Anthony.
Likewise kill the abort call in qemu_realloc(), we can just call free(ptr) for the size == 0 case to match realloc() behavior.
Signed-off-by Gerd Hoffmann <[email protected]>
--- qemu-malloc.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)
qemu-malloc.c +3 -6
@@ -45,7 +45,7 @@ void qemu_free(void *ptr)void *qemu_malloc (size_t size) {if (!size) { -abort (); + size =1 ; }return oom_check (malloc (size)); }
@@ -54,12 +54,9 @@ void *qemu_realloc(void *ptr, size_t size) {if (size) {return oom_check (realloc (ptr, size)); - }else { -if (ptr) { -return realloc (ptr, size); - } } -abort (); +free (ptr); +return NULL ; }void *qemu_mallocz (size_t size)
Signature · 1 line
1.6.2.2
Quoted 7 lines · Gerd Hoffmann
Don't abort. Return malloc(1) instead as suggested by Anthony.
Likewise kill the abort call in
qemu_realloc(), we can just call free(ptr) for the size == 0 case to matchrealloc()behavior.Signed-off-by Gerd Hoffmann <[email protected]>
Acked-by Anthony Liguori <[email protected]>
But we're going to have to get some more input from other maintainers before making a final decision.
Regards,
Anthony Liguori
Quoted 33 lines
--- qemu-malloc.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)qemu-malloc.c +3
-6@@ -45,7 +45,7 @@ void qemu_free(void *ptr)void *qemu_malloc (size_t size) {if (!size) { -abort (); + size =1 ; }return oom_check (malloc (size)); }@@ -54,12 +54,9 @@ void *qemu_realloc(void *ptr, size_t size) {if (size) {return oom_check (realloc (ptr, size)); - }else { -if (ptr) { -return realloc (ptr, size); - } } -abort (); +free (ptr); +return NULL ; }void *qemu_mallocz (size_t size)