Skip to contentSkip to conversation

qemu-io: Don't leak pattern file in error path

PATCH In review Kevin Wolf 3 participants 3 messages Sep 10, 2019

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qemu-io: Don't leak pattern file in error path

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
---
 qemu-io-cmds.c | 4 ++++
 1 file changed, 4 insertions(+)
qemu-io-cmds.c +4 -0
index d46fa166d3..349256a5fe 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kevin Wolf

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.

Quoted 6 lines

Coverity: CID 1405303

Fixes 4d731510d34f280ed45a6de621d016f67a49ea48
---
 qemu-io-cmds.c | 4 ++++
 1 file changed, 4 insertions(+)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 7 lines · Kevin Wolf

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.

Quoted 6 lines

Coverity: CID 1405303

Fixes 4d731510d34f280ed45a6de621d016f67a49ea48
---
 qemu-io-cmds.c | 4 ++++
 1 file changed, 4 insertions(+)