qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix leak in bdrv_create_file_fallback()
@ 2020-02-25 15:56 Max Reitz
  2020-02-26 13:56 ` Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Max Reitz @ 2020-02-25 15:56 UTC (permalink / raw)
  To: qemu-block; +Cc: Kevin Wolf, qemu-devel, Max Reitz

@options is leaked by the first two return statements in this function.

Note that blk_new_open() takes the reference to @options even on
failure, so all we need to do to fix the leak is to move the QDict
allocation down to where we actually need it.

Reported-by: Coverity (CID 1419884)
Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd
       ("block: Generic file creation fallback")
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 1bdb9c679d..876bd45182 100644
--- a/block.c
+++ b/block.c
@@ -600,7 +600,7 @@ static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
                                      QemuOpts *opts, Error **errp)
 {
     BlockBackend *blk;
-    QDict *options = qdict_new();
+    QDict *options;
     int64_t size = 0;
     char *buf = NULL;
     PreallocMode prealloc;
@@ -623,6 +623,7 @@ static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
         return -ENOTSUP;
     }
 
+    options = qdict_new();
     qdict_put_str(options, "driver", drv->format_name);
 
     blk = blk_new_open(filename, NULL, options,
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block: Fix leak in bdrv_create_file_fallback()
  2020-02-25 15:56 [PATCH] block: Fix leak in bdrv_create_file_fallback() Max Reitz
@ 2020-02-26 13:56 ` Kevin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2020-02-26 13:56 UTC (permalink / raw)
  To: Max Reitz; +Cc: qemu-devel, qemu-block

Am 25.02.2020 um 16:56 hat Max Reitz geschrieben:
> @options is leaked by the first two return statements in this function.
> 
> Note that blk_new_open() takes the reference to @options even on
> failure, so all we need to do to fix the leak is to move the QDict
> allocation down to where we actually need it.
> 
> Reported-by: Coverity (CID 1419884)
> Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd
>        ("block: Generic file creation fallback")
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Thanks, applied to the block branch.

Kevin



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-26 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-25 15:56 [PATCH] block: Fix leak in bdrv_create_file_fallback() Max Reitz
2020-02-26 13:56 ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).