qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] Re: [PATCH v2] loader: don't call realloc(non_null, 0) when


From: Michael S. Tsirkin
Subject: [Qemu-devel] Re: [PATCH v2] loader: don't call realloc(non_null, 0) when no symbols are present
Date: Tue, 29 Dec 2009 17:36:40 +0200
User-agent: Mutt/1.5.19 (2009-01-05)

On Mon, Dec 28, 2009 at 09:20:20PM +0100, Aurelien Jarno wrote:
> According to C99, realloc(non_null, 0) != free(non_null), that's why
> it is forbidden in QEMU.
> 
> When there are no symbols, nsyms equals to 0. Free the syms structure
> and set it to NULL instead of reallocating it with a size of 0.
> 
> This fixes -kernel with stripped kernels.
> 
> Signed-off-by: Aurelien Jarno <address@hidden>

I didn't know, you live and learn. FWIW
Acked-by: Michael S. Tsirkin <address@hidden>

BTW, which systems implement this according to C99?  glibc seems to do
free(non_null) on fedora 11.

> ---
>  hw/elf_ops.h |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/elf_ops.h b/hw/elf_ops.h
> index 6093dea..d0811ca 100644
> --- a/hw/elf_ops.h
> +++ b/hw/elf_ops.h
> @@ -149,9 +149,14 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, 
> int fd, int must_swab,
>          }
>          i++;
>      }
> -    syms = qemu_realloc(syms, nsyms * sizeof(*syms));
> +    if (nsyms) {
> +        syms = qemu_realloc(syms, nsyms * sizeof(*syms));
>  
> -    qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
> +        qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
> +    } else {
> +        free(syms);
> +        syms = NULL;
> +    }
>  
>      /* String table */
>      if (symtab->sh_link >= ehdr->e_shnum)
> -- 
> 1.6.5.3
> 
> 




reply via email to

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