thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ddf19c
From 05452efd7e0fb0522099ae09a396f8f97e66014a Mon Sep 17 00:00:00 2001
ddf19c
From: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Date: Wed, 11 Mar 2020 10:51:47 +0000
ddf19c
Subject: [PATCH 06/20] block: Fix leak in bdrv_create_file_fallback()
ddf19c
ddf19c
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
Message-id: <20200311105147.13208-7-mlevitsk@redhat.com>
ddf19c
Patchwork-id: 94229
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 6/6] block: Fix leak in bdrv_create_file_fallback()
ddf19c
Bugzilla: 1640894
ddf19c
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ddf19c
RH-Acked-by: John Snow <jsnow@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
ddf19c
From: Max Reitz <mreitz@redhat.com>
ddf19c
ddf19c
@options is leaked by the first two return statements in this function.
ddf19c
ddf19c
Note that blk_new_open() takes the reference to @options even on
ddf19c
failure, so all we need to do to fix the leak is to move the QDict
ddf19c
allocation down to where we actually need it.
ddf19c
ddf19c
Reported-by: Coverity (CID 1419884)
ddf19c
Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd
ddf19c
       ("block: Generic file creation fallback")
ddf19c
Signed-off-by: Max Reitz <mreitz@redhat.com>
ddf19c
Message-Id: <20200225155618.133412-1-mreitz@redhat.com>
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit eeea1faa099f82328f5831cf252f8ce0a59a9287)
ddf19c
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
ddf19c
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 block.c | 3 ++-
ddf19c
 1 file changed, 2 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/block.c b/block.c
ddf19c
index 3beec7f..e1a4e38 100644
ddf19c
--- a/block.c
ddf19c
+++ b/block.c
ddf19c
@@ -600,7 +600,7 @@ static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
ddf19c
                                      QemuOpts *opts, Error **errp)
ddf19c
 {
ddf19c
     BlockBackend *blk;
ddf19c
-    QDict *options = qdict_new();
ddf19c
+    QDict *options;
ddf19c
     int64_t size = 0;
ddf19c
     char *buf = NULL;
ddf19c
     PreallocMode prealloc;
ddf19c
@@ -623,6 +623,7 @@ static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
ddf19c
         return -ENOTSUP;
ddf19c
     }
ddf19c
 
ddf19c
+    options = qdict_new();
ddf19c
     qdict_put_str(options, "driver", drv->format_name);
ddf19c
 
ddf19c
     blk = blk_new_open(filename, NULL, options,
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c