From: Kevin Wolf Date: Fri, 17 Jul 2020 10:54:26 +0000 (+0200) Subject: file-posix: Fix leaked fd in raw_open_common() error path X-Git-Tag: v5.1.0-rc1~16^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8c5cf27c945d392edd85b0b0c64cd5c52cae658;p=thirdparty%2Fqemu.git file-posix: Fix leaked fd in raw_open_common() error path Signed-off-by: Kevin Wolf Message-Id: <20200717105426.51134-4-kwolf@redhat.com> Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- diff --git a/block/file-posix.c b/block/file-posix.c index 996e45ab955..8cc39a1ef61 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -773,6 +773,9 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, } ret = 0; fail: + if (ret < 0 && s->fd != -1) { + qemu_close(s->fd); + } if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) { unlink(filename); }