diff options
author | Aurelien Jarno <aurelien@aurel32.net> | 2009-12-28 21:18:12 +0100 |
---|---|---|
committer | Aurelien Jarno <aurelien@aurel32.net> | 2010-01-03 03:14:37 +0100 |
commit | 3e372cf87fa0d9ab378c3dffed6b863bef4ed7a3 (patch) | |
tree | 1d92499f74d336cbb904979c2fa095129c481fd0 /hw/elf_ops.h | |
parent | b430a22562e8a3836f984aa3f8b5b62ebd249573 (diff) | |
download | qemu-3e372cf87fa0d9ab378c3dffed6b863bef4ed7a3.zip qemu-3e372cf87fa0d9ab378c3dffed6b863bef4ed7a3.tar.gz qemu-3e372cf87fa0d9ab378c3dffed6b863bef4ed7a3.tar.bz2 |
loader: don't call realloc(non_null, 0) when no symbols are present
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 <aurelien@aurel32.net>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/elf_ops.h')
-rw-r--r-- | 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..14b9ec0 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 { + qemu_free(syms); + syms = NULL; + } /* String table */ if (symtab->sh_link >= ehdr->e_shnum) |