From patchwork Mon Dec 28 20:20:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 41861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BF87B6EEE for ; Tue, 29 Dec 2009 07:21:40 +1100 (EST) Received: from localhost ([127.0.0.1]:33184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPM5x-00054N-GB for incoming@patchwork.ozlabs.org; Mon, 28 Dec 2009 15:21:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPM4m-0004Qc-3T for qemu-devel@nongnu.org; Mon, 28 Dec 2009 15:20:24 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPM4l-0004Pb-CO for qemu-devel@nongnu.org; Mon, 28 Dec 2009 15:20:23 -0500 Received: from [199.232.76.173] (port=40114 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPM4l-0004P3-4P for qemu-devel@nongnu.org; Mon, 28 Dec 2009 15:20:23 -0500 Received: from hall.aurel32.net ([88.191.82.174]:57811) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NPM4k-0001Av-No for qemu-devel@nongnu.org; Mon, 28 Dec 2009 15:20:22 -0500 Received: from farad.aurel32.net ([82.232.2.251] helo=volta.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NPM4j-0006tT-7B for qemu-devel@nongnu.org; Mon, 28 Dec 2009 21:20:21 +0100 Received: from aurel32 by volta.aurel32.net with local (Exim 4.69) (envelope-from ) id 1NPM4i-0004px-JJ for qemu-devel@nongnu.org; Mon, 28 Dec 2009 21:20:20 +0100 Date: Mon, 28 Dec 2009 21:20:20 +0100 From: Aurelien Jarno To: qemu-devel@nongnu.org Message-ID: <20091228202020.GB4139@volta.aurel32.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH v2] loader: don't call realloc(non_null, 0) when no symbols are present X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Acked-by: Michael S. Tsirkin --- 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)