[PATCH for-5.1 3/3] file-posix: Fix leaked fd in raw_open_common() error path

Kevin Wolf posted 3 patches 5 years, 6 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
[PATCH for-5.1 3/3] file-posix: Fix leaked fd in raw_open_common() error path
Posted by Kevin Wolf 5 years, 6 months ago
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/file-posix.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 659f780570..b2ed9d7eb2 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -749,6 +749,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);
     }
-- 
2.25.4


Re: [PATCH for-5.1 3/3] file-posix: Fix leaked fd in raw_open_common() error path
Posted by Max Reitz 5 years, 6 months ago
On 17.07.20 12:54, Kevin Wolf wrote:
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/file-posix.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>