yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Fix-leak-in-bdrv_create_file_fallback.patch

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