Skip to contentSkip to conversation

block/qapi: Plug memory leak on query-block error path

PATCH In review Markus Armbruster 3 participants 4 messages Nov 20, 2015 – Nov 23, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/qapi: Plug memory leak on query-block error path

Spotted by Coverity.

---
 block/qapi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
block/qapi.c +3 -5
index d20262d..267f147 100644
@@ -436,7 +436,9 @@ BlockInfoList *qmp_query_block(Error **errp)
         bdrv_query_info(blk, &info->value, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
-            goto err;
+            g_free(info);
+            qapi_free_BlockInfoList(head);
+            return NULL;
         }
 
         *p_next = info;
@@ -444,10 +446,6 @@ BlockInfoList *qmp_query_block(Error **errp)
     }
 
     return head;
-
- err:
-    qapi_free_BlockInfoList(head);
-    return NULL;
 }
 
 BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Markus Armbruster

Spotted by Coverity.

---
 block/qapi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
block/qapi.c +0 -0
index d20262d..267f147 100644

block/qapi.c BlockInfoList *qmp_query_block(Error **errp) · line 443

Quoted 9 lines
block/qapi.c +3 -1
@@ -436,7 +436,9 @@ BlockInfoList *qmp_query_block(Error **errp)
         bdrv_query_info(blk, &info->value, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
-            goto err;
+            g_free(info);
+            qapi_free_BlockInfoList(head);
+            return NULL;
         }
 

Only info was leaked, but inlining the entire 'err' label into its one use was easier than hoisting the declaration of info out of the loop.

Quoted 13 lines
block/qapi.c +0 -4
         *p_next = info;
@@ -444,10 +446,6 @@ BlockInfoList *qmp_query_block(Error **errp)
     }
 
     return head;
-
- err:
-    qapi_free_BlockInfoList(head);
-    return NULL;
 }
 
 BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Markus Armbruster
Quoted 1 line · Markus Armbruster

Spotted by Coverity.

Worth mentioning that commit 553a7e87 was the culprit.

Quoted 6 lines
---
 block/qapi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org