diff mbox

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

Message ID 1448024015-31081-1-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Nov. 20, 2015, 12:53 p.m. UTC
Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/qapi.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Eric Blake Nov. 20, 2015, 5:57 p.m. UTC | #1
On 11/20/2015 05:53 AM, Markus Armbruster wrote:
> Spotted by Coverity.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block/qapi.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/block/qapi.c b/block/qapi.c
> index d20262d..267f147 100644
> --- a/block/qapi.c
> +++ b/block/qapi.c
> @@ -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.

Reviewed-by: Eric Blake <eblake@redhat.com>

>          *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,
>
Eric Blake Nov. 20, 2015, 6 p.m. UTC | #2
On 11/20/2015 05:53 AM, Markus Armbruster wrote:
> Spotted by Coverity.

Worth mentioning that commit 553a7e87 was the culprit.

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block/qapi.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
Kevin Wolf Nov. 23, 2015, 10:10 a.m. UTC | #3
Am 20.11.2015 um 13:53 hat Markus Armbruster geschrieben:
> Spotted by Coverity.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
diff mbox

Patch

diff --git a/block/qapi.c b/block/qapi.c
index d20262d..267f147 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -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,