[PATCH sandbox 6/9] Fix leak of file handle in libvirt-sandbox-init-common

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

If several error cases of the run_interactive method, the
sigpipe or host file descriptors could be leaked.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index c8e8379..262f4e1 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -1076,7 +1076,7 @@ run_interactive(GVirSandboxConfig *config)
     if ((host = open(devname, O_RDWR)) < 0) {
         g_printerr(_("libvirt-sandbox-init-common: cannot open %s: %s"),
                    devname, strerror(errno));
-        return -1;
+        goto cleanup;
     }
 
     tcgetattr(STDIN_FILENO, &rawattr);
@@ -1093,7 +1093,7 @@ run_interactive(GVirSandboxConfig *config)
                     gvir_sandbox_config_get_userid(config),
                     gvir_sandbox_config_get_groupid(config),
                     gvir_sandbox_config_get_homedir(config)) < 0)
-        return -1;
+        goto cleanup;
 
     command = gvir_sandbox_config_get_command(config);
     if (!eventloop(gvir_sandbox_config_interactive_get_tty(iconfig),
@@ -1112,6 +1112,8 @@ cleanup:
         close(sigpipe[0]);
     if (sigpipe[1] != -1)
         close(sigpipe[1]);
+    if (host != -1)
+        close(host);
 
     return ret;
 }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]