block/qapi: Fix memory leak in qmp_query_blockstats()
PATCH 1/1 block/qapi: Fix memory leak in qmp_query_blockstats()
For BlockBackends that are skipped in query-blockstats, we would leak info since commit 567dcb31. Allocate info only later to avoid the memory leak.
--- block/qapi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/qapi.c +2 -1
@@ -594,7 +594,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, } }else {for (blk =blk_all_next (NULL ); blk; blk =blk_all_next (blk)) { -BlockStatsList *info =g_malloc0 (sizeof (*info)); +BlockStatsList *info;AioContext *ctx =blk_get_aio_context (blk);BlockStats *s;char *qdev;
@@ -619,6 +619,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,bdrv_query_blk_stats (s->stats, blk);aio_context_release (ctx); + info =g_malloc0 (sizeof (*info)); info->value = s; *p_next = info; p_next = &info->next;
Signature · 1 line
2.13.6
Quoted 7 lines · Kevin Wolf
For BlockBackends that are skipped in query-blockstats, we would leak info since commit
567dcb31. Allocate info only later to avoid the memory leak.
Reviewed-by Alberto Garcia <[email protected]>
Berto