From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next()
Date: Fri, 20 May 2016 09:57:47 +0200 [thread overview]
Message-ID: <1463731067-7120-1-git-send-email-kwolf@redhat.com> (raw)
When all BDSes have already been iterated and we return NULL, the
iterator must be freed, too.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/block-backend.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 6928d61..c5fb251 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -329,7 +329,12 @@ BdrvNextIterator *bdrv_next(BdrvNextIterator *it, BlockDriverState **bs)
*bs = it->bs;
} while (*bs && bdrv_has_blk(*bs));
- return *bs ? it : NULL;
+ if (*bs) {
+ return it;
+ } else {
+ g_free(it);
+ return NULL;
+ }
}
/*
--
1.8.3.1
next reply other threads:[~2016-05-20 7:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-20 7:57 Kevin Wolf [this message]
2016-05-20 8:11 ` [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next() Kevin Wolf
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=1463731067-7120-1-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.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).