Skip to contentSkip to conversation

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

PATCH AlexChen 2 participants 3 messages Aug 26, 2020 – Aug 27, 2020

lore
Share & tools
lore

AlexChen

author
#0 lore raw

From: alexchen <[email protected]>

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

---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)
util/oslib-posix.c +1 -0
index ad8001a4ad..74cf5e9c73 100644
@@ -176,6 +176,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
         goto fail_unlink;
     }
 
+    close(fd);
     return true;
 
 fail_unlink:
Signature · 1 line
2.19.1
#1 lore raw
Quoted 3 lines · AlexChen

From: alexchen <[email protected]>

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.

Quoted 21 lines
---
 util/oslib-posix.c | 1 +
 1 file changed, 1 insertion(+)
util/oslib-posix.c +1 -0
index ad8001a4ad..74cf5e9c73 100644
@@ -176,6 +176,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
         goto fail_unlink;
     }
 
+    close(fd);
     return true;
 
 fail_unlink:
Signature · 1 line
2.19.1

Regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#2 lore raw
Quoted 8 lines · Daniel P. Berrangé
Quoted 3 lines · AlexChen
Quoted 3 lines

From: alexchen <[email protected]>

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