From patchwork Mon Dec 31 12:16:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 208846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9E3DD2C00A9 for ; Mon, 31 Dec 2012 23:16:40 +1100 (EST) Received: from localhost ([::1]:52589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpeII-0003tQ-Ae for incoming@patchwork.ozlabs.org; Mon, 31 Dec 2012 07:16:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpeI6-0003t0-MZ for qemu-devel@nongnu.org; Mon, 31 Dec 2012 07:16:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TpeI4-0006qv-5b for qemu-devel@nongnu.org; Mon, 31 Dec 2012 07:16:26 -0500 Received: from smtp.eu.citrix.com ([46.33.159.39]:13564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpeI4-0006qU-01 for qemu-devel@nongnu.org; Mon, 31 Dec 2012 07:16:24 -0500 X-IronPort-AV: E=Sophos;i="4.84,385,1355097600"; d="scan'208";a="396011" Received: from lonpmailmx01.citrite.net ([10.30.203.162]) by LONPIPO01.EU.CITRIX.COM with ESMTP/TLS/RC4-MD5; 31 Dec 2012 12:16:22 +0000 Received: from mac.citrite.net (10.31.3.229) by LONPMAILMX01.citrite.net (10.30.203.162) with Microsoft SMTP Server id 8.3.279.5; Mon, 31 Dec 2012 12:16:21 +0000 From: Roger Pau Monne To: Date: Mon, 31 Dec 2012 13:16:13 +0100 Message-ID: <1356956174-23548-3-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 1.7.7.5 (Apple Git-26) In-Reply-To: <1356956174-23548-1-git-send-email-roger.pau@citrix.com> References: <1356956174-23548-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 46.33.159.39 Cc: Anthony PERARD , xen-devel@lists.xen.org, Stefano Stabellini , Roger Pau Monne Subject: [Qemu-devel] [PATCH RFC 2/3] xen_disk: fix memory leak 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On ioreq_release the full ioreq was memset to 0, loosing all the data and memory allocations inside the QEMUIOVector, which leads to a memory leak. Create a new function to specifically reset ioreq. Reported-by: Maik Wessler Signed-off-by: Roger Pau Monné Cc: xen-devel@lists.xen.org Cc: Stefano Stabellini Cc: Anthony PERARD Acked-by: Stefano Stabellini --- hw/xen_disk.c | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/hw/xen_disk.c b/hw/xen_disk.c index a159ee5..1eb485a 100644 --- a/hw/xen_disk.c +++ b/hw/xen_disk.c @@ -113,6 +113,31 @@ struct XenBlkDev { /* ------------------------------------------------------------- */ +static void ioreq_reset(struct ioreq *ioreq) +{ + memset(&ioreq->req, 0, sizeof(ioreq->req)); + ioreq->status = 0; + ioreq->start = 0; + ioreq->presync = 0; + ioreq->postsync = 0; + ioreq->mapped = 0; + + memset(ioreq->domids, 0, sizeof(ioreq->domids)); + memset(ioreq->refs, 0, sizeof(ioreq->refs)); + ioreq->prot = 0; + memset(ioreq->page, 0, sizeof(ioreq->page)); + ioreq->pages = NULL; + + ioreq->aio_inflight = 0; + ioreq->aio_errors = 0; + + ioreq->blkdev = NULL; + memset(&ioreq->list, 0, sizeof(ioreq->list)); + memset(&ioreq->acct, 0, sizeof(ioreq->acct)); + + qemu_iovec_reset(&ioreq->v); +} + static struct ioreq *ioreq_start(struct XenBlkDev *blkdev) { struct ioreq *ioreq = NULL; @@ -130,7 +155,6 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev) /* get one from freelist */ ioreq = QLIST_FIRST(&blkdev->freelist); QLIST_REMOVE(ioreq, list); - qemu_iovec_reset(&ioreq->v); } QLIST_INSERT_HEAD(&blkdev->inflight, ioreq, list); blkdev->requests_inflight++; @@ -154,7 +178,7 @@ static void ioreq_release(struct ioreq *ioreq, bool finish) struct XenBlkDev *blkdev = ioreq->blkdev; QLIST_REMOVE(ioreq, list); - memset(ioreq, 0, sizeof(*ioreq)); + ioreq_reset(ioreq); ioreq->blkdev = blkdev; QLIST_INSERT_HEAD(&blkdev->freelist, ioreq, list); if (finish) {