]> git.proxmox.com Git - mirror_qemu.git/commitdiff
loader: don't call realloc(non_null, 0) when no symbols are present
authorAurelien Jarno <aurelien@aurel32.net>
Mon, 28 Dec 2009 20:18:12 +0000 (21:18 +0100)
committerAurelien Jarno <aurelien@aurel32.net>
Sun, 3 Jan 2010 02:14:37 +0000 (03:14 +0100)
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>
hw/elf_ops.h

index 6093deaa730710449e8a856a3c817bd6ee835ee3..14b9ec04446268c92020b94c5ce12fd340a1a897 100644 (file)
@@ -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)