From patchwork Thu May 28 12:08:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 49083 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E6251218EC for ; Thu, 28 May 2015 12:23:11 +0000 (UTC) Received: by wizk4 with SMTP id k4sf13375211wiz.2 for ; Thu, 28 May 2015 05:23:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:content-type:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=sF4GetOTCLZV8nY90dzwxUeahBvaj8zDTRElxobwbUU=; b=DErgYXABCvrBlUl8qBPt/UqEGBt1Y3tfoUOgO614hJHWOof1qQXyytTYcfRFknjsWr ZdOFWENUY6ZiMHLLojRik4nJthYPgtN63nQp5wz+rqrqai1KEdmBhr9c5gkCbgh87coC vvwg4yflHAKnTTcn9Oa7Op0lSiCFcCaGQZUaAhPv4oynhylM/cKG9U5J63IG7iwxJLNu R31KoJKsUAsnjIQ98MrgtwptH5E2du5vurhjVcZlvtt2UQ3RGNOr814hPOWQ6VlkSj8L rN2XQMyd1gFaVgVWYFClmmwBzM9wJeeChdqItLi6U1xcHdIyRC22fUfbktEbqnvkI+NC tOqw== X-Gm-Message-State: ALoCoQl+OgG9a6WM8wScdtx3Sx/t8X7KtEP/L4ltU7+npV4iobRh7ASPfWGF8CCrlNjIUboGTiHk X-Received: by 10.180.106.136 with SMTP id gu8mr33030989wib.6.1432815791171; Thu, 28 May 2015 05:23:11 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.105 with SMTP id lb9ls182949lab.10.gmail; Thu, 28 May 2015 05:23:11 -0700 (PDT) X-Received: by 10.152.3.97 with SMTP id b1mr2555518lab.54.1432815791040; Thu, 28 May 2015 05:23:11 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id gk6si1792222lbc.173.2015.05.28.05.23.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2015 05:23:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labko7 with SMTP id ko7so26597287lab.2 for ; Thu, 28 May 2015 05:23:11 -0700 (PDT) X-Received: by 10.112.220.7 with SMTP id ps7mr2486031lbc.72.1432815790954; Thu, 28 May 2015 05:23:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1114469lbb; Thu, 28 May 2015 05:23:10 -0700 (PDT) X-Received: by 10.55.33.24 with SMTP id h24mr4469188qkh.95.1432815789663; Thu, 28 May 2015 05:23:09 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e144si2147689qhc.127.2015.05.28.05.23.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 28 May 2015 05:23:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yxwq4-0007go-MB for patch@linaro.org; Thu, 28 May 2015 08:23:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yxwe9-0002H3-6B for qemu-devel@nongnu.org; Thu, 28 May 2015 08:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yxwe4-0003c9-F7 for qemu-devel@nongnu.org; Thu, 28 May 2015 08:10:49 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:45279) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yxwe3-0003ZD-RD; Thu, 28 May 2015 08:10:44 -0400 Received: from 172.24.2.119 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id COP98111; Thu, 28 May 2015 20:10:33 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.158.1; Thu, 28 May 2015 20:10:07 +0800 From: Shannon Zhao To: Date: Thu, 28 May 2015 20:08:38 +0800 Message-ID: <1432814932-12608-16-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1432814932-12608-1-git-send-email-zhaoshenglong@huawei.com> References: <1432814932-12608-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Cc: qemu-trivial@nongnu.org, pbonzini@redhat.com, mjt@tls.msk.ru, shannon.zhao@linaro.org, peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH 15/29] hw/mips/mips_jazz.c: Fix memory leak spotted by valgrind X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Shannon Zhao valgrind complains about: ==28487== 1,568 (128 direct, 1,440 indirect) bytes in 1 blocks are definitely lost in loss record 2,160 of 2,212 ==28487== at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==28487== by 0x2F5B97: malloc_and_trace (vl.c:2556) ==28487== by 0x64C770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3) ==28487== by 0x384303: qemu_extend_irqs (irq.c:55) ==28487== by 0x38438F: qemu_allocate_irqs (irq.c:64) ==28487== by 0x3B81DD: rc4030_init (rc4030.c:806) ==28487== by 0x240151: mips_jazz_init (mips_jazz.c:221) ==28487== by 0x240898: mips_magnum_init (mips_jazz.c:341) ==28487== by 0x2F9F62: main (vl.c:4249) ==28487== 32 bytes in 1 blocks are definitely lost in loss record 1,359 of 2,212 ==28487== at 0x4C2845D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==28487== by 0x2F5B97: malloc_and_trace (vl.c:2556) ==28487== by 0x64C71F5: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3) ==28487== by 0x64C7766: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.3600.3) ==28487== by 0x3B8132: rc4030_allocate_dmas (rc4030.c:787) ==28487== by 0x3B81F5: rc4030_init (rc4030.c:807) ==28487== by 0x240151: mips_jazz_init (mips_jazz.c:221) ==28487== by 0x240898: mips_magnum_init (mips_jazz.c:341) ==28487== by 0x2F9F62: main (vl.c:4249) Signed-off-by: Shannon Zhao Signed-off-by: Shannon Zhao --- hw/dma/rc4030.c | 2 +- hw/mips/mips_jazz.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/dma/rc4030.c b/hw/dma/rc4030.c index af26632..9b42aab 100644 --- a/hw/dma/rc4030.c +++ b/hw/dma/rc4030.c @@ -803,7 +803,7 @@ void *rc4030_init(qemu_irq timer, qemu_irq jazz_bus, s = g_malloc0(sizeof(rc4030State)); - *irqs = qemu_allocate_irqs(rc4030_irq_jazz_request, s, 16); + *irqs = qemu_allocate_irqs(rc4030_irq_jazz_request, s, 10); *dmas = rc4030_allocate_dmas(s, 4); s->periodic_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rc4030_periodic_timer, s); diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c index 2c153e0..cd26f60 100644 --- a/hw/mips/mips_jazz.c +++ b/hw/mips/mips_jazz.c @@ -261,8 +261,10 @@ static void mips_jazz_init(MachineState *machine, break; case JAZZ_PICA61: isa_vga_mm_init(0x40000000, 0x60000000, 0, get_system_memory()); + qemu_free_irq(rc4030[3]); break; default: + qemu_free_irq(rc4030[3]); break; } @@ -288,6 +290,7 @@ static void mips_jazz_init(MachineState *machine, esp_init(0x80002000, 0, rc4030_dma_read, rc4030_dma_write, dmas[0], rc4030[5], &esp_reset, &dma_enable); + g_free(dmas); /* Floppy */ if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) { @@ -312,18 +315,28 @@ static void mips_jazz_init(MachineState *machine, if (serial_hds[0]) { serial_mm_init(address_space, 0x80006000, 0, rc4030[8], 8000000/16, serial_hds[0], DEVICE_NATIVE_ENDIAN); + } else { + qemu_free_irq(rc4030[8]); } + if (serial_hds[1]) { serial_mm_init(address_space, 0x80007000, 0, rc4030[9], 8000000/16, serial_hds[1], DEVICE_NATIVE_ENDIAN); + } else { + qemu_free_irq(rc4030[9]); } /* Parallel port */ - if (parallel_hds[0]) + if (parallel_hds[0]) { parallel_mm_init(address_space, 0x80008000, 0, rc4030[0], parallel_hds[0]); + } else { + qemu_free_irq(rc4030[0]); + } /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */ + qemu_free_irq(rc4030[2]); + g_free(rc4030); /* NVRAM */ dev = qdev_create(NULL, "ds1225y");