From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, dplotnikov@virtuozzo.com,
qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH] qemu-io: Don't leak pattern file in error path
Date: Tue, 10 Sep 2019 09:09:49 +0200 [thread overview]
Message-ID: <20190910070949.16256-1-kwolf@redhat.com> (raw)
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
next reply other threads:[~2019-09-10 7:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 7:09 Kevin Wolf [this message]
2019-09-10 7:45 ` [Qemu-devel] [PATCH] qemu-io: Don't leak pattern file in error path Max Reitz
2019-09-10 9:33 ` [Qemu-devel] [Qemu-block] " Stefano Garzarella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190910070949.16256-1-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=dplotnikov@virtuozzo.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).