All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next()
@ 2016-05-20  7:57 Kevin Wolf
  2016-05-20  8:11 ` Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2016-05-20  7:57 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, qemu-devel

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next()
  2016-05-20  7:57 [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next() Kevin Wolf
@ 2016-05-20  8:11 ` Kevin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2016-05-20  8:11 UTC (permalink / raw)
  To: qemu-block; +Cc: qemu-devel

Am 20.05.2016 um 09:57 hat Kevin Wolf geschrieben:
> 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>

NACK, this doesn't fix cases where the caller exists loop prematurely.

Kevin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-20  8:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-20  7:57 [Qemu-devel] [PATCH] block: Fix memory leak in bdrv_next() Kevin Wolf
2016-05-20  8:11 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.