qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] fix qemu_malloc(0)


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] fix qemu_malloc(0)
Date: Fri, 29 May 2009 04:39:10 -0500
User-agent: Thunderbird 2.0.0.21 (X11/20090409)

Gerd Hoffmann wrote:
> 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 <address@hidden>
>   

Acked-by: Anthony Liguori <address@hidden>

But we're going to have to get some more input from other maintainers
before making a final decision.

Regards,

Anthony Liguori

> ---
>  qemu-malloc.c |    9 +++------
>  1 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/qemu-malloc.c b/qemu-malloc.c
> index 295d185..4193fdb 100644
> --- a/qemu-malloc.c
> +++ b/qemu-malloc.c
> @@ -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)
>   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]