From patchwork Thu Nov 8 18:33:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10674849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96B0D1709 for ; Thu, 8 Nov 2018 18:34:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D7542E2C6 for ; Thu, 8 Nov 2018 18:34:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71E512E2CF; Thu, 8 Nov 2018 18:34:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D05A72E309 for ; Thu, 8 Nov 2018 18:34:37 +0000 (UTC) Received: from localhost ([::1]:58490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKp8W-0006cA-Nn for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Nov 2018 13:34:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKp7n-0006KB-H2 for qemu-devel@nongnu.org; Thu, 08 Nov 2018 13:33:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKp7j-0002fe-5K for qemu-devel@nongnu.org; Thu, 08 Nov 2018 13:33:51 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46863) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKp7i-0002Jp-Gf for qemu-devel@nongnu.org; Thu, 08 Nov 2018 13:33:46 -0500 Received: by mail-pf1-x444.google.com with SMTP id s9-v6so2328107pfm.13 for ; Thu, 08 Nov 2018 10:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:cc:from:to; bh=iBjHEPXpN01EyxwdYIxLAOVHM7JWcXN+GB8zUqvN+t4=; b=cPk6cw8dYR90sr5yGkJ3KzlLM0JWlyzJUsfOpRoWlMrYEHXN/ZkC9ERwhYf4Cuh3m6 +3SzAxynrS1HWXxwGvYkqr016cygNEAQJ2eH3ZVQol0HgA49vBAuRbPogxcgbGDanNaB qquMFiP3zz/58vXJDoyRA9emhxv+mr6ja3GteKiUoGRUgOSBBwBp46+pxbzuDUe7WSfd /w6Id+1LDgzqnzCUK8jT0LmlFNBlB+Rrf7ycT10Anrx2eXlv/+51HEFZ0Xp2OBR8Jwu2 X1wkDhsIRsG/c+w7UMbqQUKDf7s5YbUQWGEJ9HXtLyaGiTD7EMA/ARyOXnp0lsPL9/kO UGfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=iBjHEPXpN01EyxwdYIxLAOVHM7JWcXN+GB8zUqvN+t4=; b=hKoZMSQKedPn4N2O09YCh/nThHc0n8YHZ+SGPzMXQkZFTxXak99fukkEysKe/oScCE h/LRtF4GlQwDxEJ7FH/OH23Sp/GAbDyXM9yCTqnpEiYdfXteVz3VLdu+VSzLmjyKqs/4 Pi3zqqA11rDpVivg4/1fRNGoRoEh0T4ILaDjLIjXR26tECEsoTwkOX43VrtWhaV7C3jq vYlhFBMkq5BZLwLyBdLdEGehu8DsDrFh1+tbqXOH5z3/wUROd0M6UHDDHGXgSsYjDsRz VaZx6ChWWwI+O1wfmCqWz8UvQfrpyYqHzy91uvnFN9tZXAw7P0AUzMc+R9yiXpSb4l9x USQA== X-Gm-Message-State: AGRZ1gK95N4MnU2knZE5cdPlEhcvKhHLpCZshfRtVT5PK1E0kiQq+539 6HzC7cPlBkxYNwnCRvfR5pFgIOoxf7M= X-Google-Smtp-Source: AJdET5f7dV+9a9Y6X3ZNcIOggZAFdgLQ4F+bDH/9Sfgs8eFtAPO2gYBdIZbPObybfAzUO4kAaqsF5g== X-Received: by 2002:a63:ee0e:: with SMTP id e14mr4563339pgi.8.1541702001138; Thu, 08 Nov 2018 10:33:21 -0800 (PST) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id h2-v6sm4816559pfc.6.2018.11.08.10.33.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:33:20 -0800 (PST) Date: Thu, 8 Nov 2018 10:33:06 -0800 Message-Id: <20181108183306.4361-2-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181108183306.4361-1-palmer@sifive.com> References: <20181108183306.4361-1-palmer@sifive.com> From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PULL] riscv: spike: Fix memory leak in the board init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , Palmer Dabbelt , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alistair Francis Coverity caught a malloc() call that was never freed. This patch ensures that we free the memory but also updates the allocation to use g_strdup_printf() instead of malloc(). Signed-off-by: Alistair Francis Suggested-by: Peter Maydell Reviewed-by: Peter Maydell Reviewed-by: Palmer Dabbelt Signed-off-by: Palmer Dabbelt --- hw/riscv/spike.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index 8a712ed49026..268df04c3c7d 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -316,9 +316,7 @@ static void spike_v1_09_1_board_init(MachineState *machine) /* build config string with supplied memory size */ char *isa = riscv_isa_string(&s->soc.harts[0]); - size_t config_string_size = strlen(config_string_tmpl) + 48; - char *config_string = malloc(config_string_size); - snprintf(config_string, config_string_size, config_string_tmpl, + char *config_string = g_strdup_printf(config_string_tmpl, (uint64_t)memmap[SPIKE_CLINT].base + SIFIVE_TIME_BASE, (uint64_t)memmap[SPIKE_DRAM].base, (uint64_t)ram_size, isa, @@ -345,6 +343,8 @@ static void spike_v1_09_1_board_init(MachineState *machine) /* Core Local Interruptor (timer and IPI) */ sifive_clint_create(memmap[SPIKE_CLINT].base, memmap[SPIKE_CLINT].size, smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE); + + g_free(config_string); } static void spike_v1_09_1_machine_init(MachineClass *mc)