qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: qemu-devel@nongnu.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	xen-devel@lists.xen.org,
	Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [Qemu-devel] [PATCH RFC 2/3] xen_disk: fix memory leak
Date: Mon, 31 Dec 2012 13:16:13 +0100	[thread overview]
Message-ID: <1356956174-23548-3-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1356956174-23548-1-git-send-email-roger.pau@citrix.com>

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 <maik.wessler@yahoo.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: xen-devel@lists.xen.org
Cc: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Cc: Anthony PERARD <anthony.perard@citrix.com>
---
 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) {
-- 
1.7.7.5 (Apple Git-26)

  parent reply	other threads:[~2012-12-31 12:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31 12:16 [Qemu-devel] [PATCH RFC 0/3] xen pv disk persistent grants implementation Roger Pau Monne
2012-12-31 12:16 ` [Qemu-devel] [PATCH RFC 1/3] xen_disk: handle disk files on ramfs/tmpfs Roger Pau Monne
2013-01-03 14:21   ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2013-01-03 14:28   ` Ian Campbell
2013-01-04 14:54     ` Stefano Stabellini
2013-01-04 15:05       ` Roger Pau Monné
2013-01-04 15:30         ` Stefano Stabellini
2012-12-31 12:16 ` Roger Pau Monne [this message]
2013-01-04 15:06   ` [Qemu-devel] [PATCH RFC 2/3] xen_disk: fix memory leak Stefano Stabellini
2012-12-31 12:16 ` [Qemu-devel] [PATCH RFC 3/3] xen_disk: add persistent grant support to xen_disk backend Roger Pau Monne
2013-01-04 16:42   ` Stefano Stabellini
2013-01-04 17:37     ` Roger Pau Monné
2013-01-04 18:02       ` Stefano Stabellini
2013-01-04 21:01   ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356956174-23548-3-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=Stefano.Stabellini@eu.citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).