[PULL,20/22] qemu-io: Don't leak pattern file in error path
diff mbox series

Message ID 20190912134604.22019-21-kwolf@redhat.com
State New
Headers show
  • [PULL,01/22] qcow2: Fix the calculation of the maximum L2 cache size
Related show

Commit Message

Kevin Wolf Sept. 12, 2019, 1:46 p.m. UTC
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>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
 qemu-io-cmds.c | 4 ++++
 1 file changed, 4 insertions(+)

diff mbox series

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,
+    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,
+    if (f) {
+        fclose(f);
+    }
     return NULL;