qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-io: Don't leak pattern file in error path
@ 2019-09-10  7:09 Kevin Wolf
  2019-09-10  7:45 ` Max Reitz
  2019-09-10  9:33 ` [Qemu-devel] [Qemu-block] " Stefano Garzarella
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2019-09-10  7:09 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, dplotnikov, qemu-devel, mreitz

qemu_io_alloc_from_file() needs to close the pattern file even if some
error occurred.

Setting f = NULL in the success path and checking it for NULL in the
error path isn't strictly necessary at this point, but let's do it
anyway in case someone later adds a 'goto error' after closing the file.

Coverity: CID 1405303
Fixes: 4d731510d34f280ed45a6de621d016f67a49ea48
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-io-cmds.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index d46fa166d3..349256a5fe 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -401,6 +401,7 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
     }
 
     fclose(f);
+    f = NULL;
 
     if (len > pattern_len) {
         len -= pattern_len;
@@ -420,6 +421,9 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
 
 error:
     qemu_io_free(buf_origin);
+    if (f) {
+        fclose(f);
+    }
     return NULL;
 }
 
-- 
2.20.1



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

end of thread, other threads:[~2019-09-10  9:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-10  7:09 [Qemu-devel] [PATCH] qemu-io: Don't leak pattern file in error path Kevin Wolf
2019-09-10  7:45 ` Max Reitz
2019-09-10  9:33 ` [Qemu-devel] [Qemu-block] " Stefano Garzarella

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).