xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Daley <mattd@bugfuzz.com>
To: xen-devel@lists.xen.org
Cc: ilon@medinet.se, "Ian Campbell" <Ian.Campbell@citrix.com>,
	"Stefano Stabellini" <stefano.stabellini@eu.citrix.com>,
	"Matthew Daley" <mattd@bugfuzz.com>,
	"Ian Jackson" <Ian.Jackson@eu.citrix.com>,
	"Niklas Bivald" <niklas@bivald.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH] xen_disk: fix memory leak
Date: Wed,  4 Dec 2013 15:16:18 +1300	[thread overview]
Message-ID: <1386123378-12699-1-git-send-email-mattd@bugfuzz.com> (raw)
In-Reply-To: <1386069032.13256.10.camel@kazak.uk.xensource.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>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Backport to qemu-xen-traditional.

Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
---
 hw/xen_disk.c |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index ee8d36f..250d806 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -116,6 +116,29 @@ 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;
+
+    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));
+
+    qemu_iovec_reset(&ioreq->v);
+}
+
 static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
 {
     struct ioreq *ioreq = NULL;
@@ -132,7 +155,6 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
 	/* get one from freelist */
 	ioreq = LIST_FIRST(&blkdev->freelist);
 	LIST_REMOVE(ioreq, list);
-        qemu_iovec_reset(&ioreq->v);
     }
     LIST_INSERT_HEAD(&blkdev->inflight, ioreq, list);
     blkdev->requests_inflight++;
@@ -156,7 +178,7 @@ static void ioreq_release(struct ioreq *ioreq, bool finish)
     struct XenBlkDev *blkdev = ioreq->blkdev;
 
     LIST_REMOVE(ioreq, list);
-    memset(ioreq, 0, sizeof(*ioreq));
+    ioreq_reset(ioreq);
     ioreq->blkdev = blkdev;
     LIST_INSERT_HEAD(&blkdev->freelist, ioreq, list);
     if (finish) {
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2013-12-04  2:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 14:57 Possible memory leak in qemu-dm (qemu-dm swapping 20GB+, adding 2gb+ per day) Niklas Bivald
2013-11-22  1:49 ` Matthew Daley
2013-11-25  9:48   ` Niklas Bivald
2013-11-25 11:58     ` Ian Jackson
2013-11-25 12:32       ` Niklas Bivald
2013-11-25 12:40         ` Ian Jackson
2013-11-25 12:59           ` Niklas Bivald
2013-11-27  9:49             ` Niklas Bivald
2013-11-27 10:32               ` Fabio Fantoni
2013-11-27 11:06             ` Ian Campbell
2013-12-02 20:49               ` Niklas Bivald
2013-12-02 22:24                 ` Matthew Daley
2013-12-03  8:27                   ` Niklas Bivald
2013-12-03 11:10                   ` Ian Campbell
2013-12-04  2:16                     ` Matthew Daley [this message]
2013-12-04  3:35                       ` [PATCH] xen_disk: fix memory leak Matthew Daley
2013-12-04 11:15                         ` Stefano Stabellini
2013-12-04 11:26                           ` Matthew Daley
2013-12-04 11:35                             ` Stefano Stabellini
2013-12-04 11:38                               ` Matthew Daley
2013-12-04 11:41                               ` Ian Campbell
2013-12-04 11:49                                 ` Matthew Daley
2013-12-04 14:46                       ` Ian Jackson

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=1386123378-12699-1-git-send-email-mattd@bugfuzz.com \
    --to=mattd@bugfuzz.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=ilon@medinet.se \
    --cc=niklas@bivald.com \
    --cc=roger.pau@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --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).