oslib-posix:Fix handle fd leak in qemu_write_pidfile()

AlexChen posted 1 patch 3 years, 8 months ago
Test docker-quick@centos7 failed
Test docker-mingw@fedora failed
Test checkpatch failed
Test FreeBSD failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/5F463618.10000@huawei.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
util/oslib-posix.c | 1 +
1 file changed, 1 insertion(+)
oslib-posix:Fix handle fd leak in qemu_write_pidfile()
Posted by AlexChen 3 years, 8 months ago
From: alexchen <alex.chen@huawei.com>

The fd will leak when (a.st_ino == b.st_ino) is true, fix it.

Signed-off-by: AlexChen <alex.chen@huawei.com>
---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index ad8001a4ad..74cf5e9c73 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -176,6 +176,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
         goto fail_unlink;
     }

+    close(fd);
     return true;

 fail_unlink:
-- 
2.19.1


Re: oslib-posix:Fix handle fd leak in qemu_write_pidfile()
Posted by Daniel P. Berrangé 3 years, 8 months ago
On Wed, Aug 26, 2020 at 06:14:48PM +0800, AlexChen wrote:
> From: alexchen <alex.chen@huawei.com>
> 
> The fd will leak when (a.st_ino == b.st_ino) is true, fix it.

That is *INTENTIONAL*.  We're holding a lock on the file and the
lock exists only while the FD is open.  When QEMU exists, the FD
is closed and the lock is released. There is no leak.

> Signed-off-by: AlexChen <alex.chen@huawei.com>
> ---
>  util/oslib-posix.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index ad8001a4ad..74cf5e9c73 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -176,6 +176,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
>          goto fail_unlink;
>      }
> 
> +    close(fd);
>      return true;
> 
>  fail_unlink:
> -- 
> 2.19.1
> 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: oslib-posix:Fix handle fd leak in qemu_write_pidfile()
Posted by AlexChen 3 years, 8 months ago
On 2020/8/26 18:18, Daniel P. Berrangé wrote:
> On Wed, Aug 26, 2020 at 06:14:48PM +0800, AlexChen wrote:
>> > From: alexchen <alex.chen@huawei.com>
>> > 
>> > The fd will leak when (a.st_ino == b.st_ino) is true, fix it.
> That is *INTENTIONAL*.  We're holding a lock on the file and the
> lock exists only while the FD is open.  When QEMU exists, the FD
> is closed and the lock is released. There is no leak.
> 
OK, I got it, thanks.

Thanks
Alex