From patchwork Tue Jul 5 02:16:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 71367 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp75757qgy; Mon, 4 Jul 2016 19:18:50 -0700 (PDT) X-Received: by 10.55.107.6 with SMTP id g6mr19685661qkc.166.1467685130008; Mon, 04 Jul 2016 19:18:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v35si858192qtb.4.2016.07.04.19.18.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 04 Jul 2016 19:18:50 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:51489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKFwn-0004Ba-JA for patch@linaro.org; Mon, 04 Jul 2016 22:18:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKFvl-0003v2-Ra for qemu-devel@nongnu.org; Mon, 04 Jul 2016 22:17:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKFvh-0007I0-Gt for qemu-devel@nongnu.org; Mon, 04 Jul 2016 22:17:44 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:30240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKFvg-0007HS-SD for qemu-devel@nongnu.org; Mon, 04 Jul 2016 22:17:41 -0400 Received: from 172.24.1.137 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.137]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DJT65304; Tue, 05 Jul 2016 10:17:16 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Tue, 5 Jul 2016 10:17:07 +0800 From: Shannon Zhao To: Date: Tue, 5 Jul 2016 10:16:38 +0800 Message-ID: <1467684998-12076-1-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.577B18AD.0057, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 3b207cb867522a8cce667d5d1cd62d2a X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH] hw/block/m25p80: fix resource leak 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: peter.maydell@linaro.org, pbonzini@redhat.com, shannon.zhao@linaro.org, crosthwaite.peter@gmail.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Shannon Zhao These two are spot by Coverity 1357232 and 1357233. Signed-off-by: Shannon Zhao --- hw/block/m25p80.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.0.4 diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index d9b2793..ca8c12c 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -459,12 +459,13 @@ static void blk_sync_complete(void *opaque, int ret) static void flash_sync_page(Flash *s, int page) { - QEMUIOVector *iov = g_new(QEMUIOVector, 1); + QEMUIOVector *iov; if (!s->blk || blk_is_read_only(s->blk)) { return; } + iov = g_new(QEMUIOVector, 1); qemu_iovec_init(iov, 1); qemu_iovec_add(iov, s->storage + page * s->pi->page_size, s->pi->page_size); @@ -474,13 +475,14 @@ static void flash_sync_page(Flash *s, int page) static inline void flash_sync_area(Flash *s, int64_t off, int64_t len) { - QEMUIOVector *iov = g_new(QEMUIOVector, 1); + QEMUIOVector *iov; if (!s->blk || blk_is_read_only(s->blk)) { return; } assert(!(len % BDRV_SECTOR_SIZE)); + iov = g_new(QEMUIOVector, 1); qemu_iovec_init(iov, 1); qemu_iovec_add(iov, s->storage + off, len); blk_aio_pwritev(s->blk, off, iov, 0, blk_sync_complete, iov);