When all BDSes have already been iterated and we return NULL, the iterator must be freed, too.
Signed-off-by: Kevin Wolf <kw...@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