[PATCH 1/2] qemuMonitorOpenUnix: Refactor cleanup

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

 



Use VIR_AUTOFREE for the temp socket so that the 'error:' label can be
removed.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index fcd39b80c6..04b5cce6fb 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -233,7 +233,7 @@ qemuMonitorOpenUnix(const char *monitor,
                     unsigned long long timeout)
 {
     struct sockaddr_un addr;
-    int monfd;
+    VIR_AUTOCLOSE monfd = -1;
     virTimeBackOffVar timebackoff;
     int ret = -1;

@@ -248,12 +248,12 @@ qemuMonitorOpenUnix(const char *monitor,
     if (virStrcpyStatic(addr.sun_path, monitor) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Monitor path %s too big for destination"), monitor);
-        goto error;
+        return -1;
     }

     if (retry) {
         if (virTimeBackOffStart(&timebackoff, 1, timeout * 1000) < 0)
-            goto error;
+            return -1;
         while (virTimeBackOffWait(&timebackoff)) {
             ret = connect(monfd, (struct sockaddr *)&addr, sizeof(addr));

@@ -269,28 +269,27 @@ qemuMonitorOpenUnix(const char *monitor,

             virReportSystemError(errno, "%s",
                                  _("failed to connect to monitor socket"));
-            goto error;
+            return -1;
         }

         if (ret != 0) {
             virReportSystemError(errno, "%s",
                                  _("monitor socket did not show up"));
-            goto error;
+            return -1;
         }
     } else {
         ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));
         if (ret < 0) {
             virReportSystemError(errno, "%s",
                                  _("failed to connect to monitor socket"));
-            goto error;
+            return -1;
         }
     }

-    return monfd;
+    ret = monfd;
+    monfd = -1;

- error:
-    VIR_FORCE_CLOSE(monfd);
-    return -1;
+    return ret;
 }


-- 
2.34.1




[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]

  Powered by Linux