From patchwork Thu Jul 7 13:48:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9218985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1C69260574 for ; Thu, 7 Jul 2016 13:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FD0E262F2 for ; Thu, 7 Jul 2016 13:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A88263DC; Thu, 7 Jul 2016 13:52:59 +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=-6.9 required=2.0 tests=BAYES_00,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 83DF3262F2 for ; Thu, 7 Jul 2016 13:52:58 +0000 (UTC) Received: from localhost ([::1]:40068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bL9jd-0000Vu-Np for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Jul 2016 09:52:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bL9fx-0003mO-MK for qemu-devel@nongnu.org; Thu, 07 Jul 2016 09:49:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bL9fu-0001tY-G3 for qemu-devel@nongnu.org; Thu, 07 Jul 2016 09:49:08 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58123) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bL9fu-0001s4-8l for qemu-devel@nongnu.org; Thu, 07 Jul 2016 09:49:06 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bL9fo-0004aO-8l for qemu-devel@nongnu.org; Thu, 07 Jul 2016 14:49:00 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 14:48:56 +0100 Message-Id: <1467899337-19192-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467899337-19192-1-git-send-email-peter.maydell@linaro.org> References: <1467899337-19192-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 5/6] 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Shannon Zhao These two are spot by Coverity 1357232 and 1357233. Signed-off-by: Shannon Zhao Message-id: 1467684998-12076-1-git-send-email-zhaoshenglong@huawei.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/block/m25p80.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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);