Skip to contentSkip to conversation

block: Fix memory leak in bdrv_next()

PATCH Superseded Kevin Wolf 1 participant 2 messages May 20, 2016 Block layer

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Fix memory leak in bdrv_next()

When all BDSes have already been iterated and we return NULL, the iterator must be freed, too.

---
 block/block-backend.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
block/block-backend.c +6 -1
index 6928d61..c5fb251 100644
@@ -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;
+    }
 }
 
 /*
Signature · 1 line
1.8.3.1
author NAK
#1 lore raw

Am 20.05.2016 um 09:57 hat Kevin Wolf geschrieben:

Quoted 4 lines

When all BDSes have already been iterated and we return NULL, the iterator must be freed, too.

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

Kevin