[PATCH 02/25] virLogDaemonPreExecRestart: Refactor memory cleanup

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

 



Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/logging/log_daemon.c | 54 +++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 31 deletions(-)

diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 770f6dd273..ceffa6a368 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -505,62 +505,54 @@ virLogDaemonPreExecRestart(const char *state_file,
                            virNetDaemonPtr dmn,
                            char **argv)
 {
-    virJSONValuePtr child;
-    char *state = NULL;
-    virJSONValuePtr object = virJSONValueNewObject();
-    char *magic = NULL;
+    g_autoptr(virJSONValue) object = virJSONValueNewObject();
+    g_autoptr(virJSONValue) daemon = NULL;
+    g_autoptr(virJSONValue) handler = NULL;
+    g_autofree char *state = NULL;
+    g_autofree char *magic = NULL;

     VIR_DEBUG("Running pre-restart exec");

-    if (!(child = virNetDaemonPreExecRestart(dmn)))
-        goto cleanup;
+    if (!(daemon = virNetDaemonPreExecRestart(dmn)))
+        return -1;

-    if (virJSONValueObjectAppend(object, "daemon", child) < 0) {
-        virJSONValueFree(child);
-        goto cleanup;
-    }
+    if (virJSONValueObjectAppend(object, "daemon", daemon) < 0)
+        return -1;
+    daemon = NULL;

     if (!(magic = virLogDaemonGetExecRestartMagic()))
-        goto cleanup;
+        return -1;

     if (virJSONValueObjectAppendString(object, "magic", magic) < 0)
-        goto cleanup;
-
-    if (!(child = virLogHandlerPreExecRestart(logDaemon->handler)))
-        goto cleanup;
+        return -1;

-    if (virJSONValueObjectAppend(object, "handler", child) < 0) {
-        virJSONValueFree(child);
-        goto cleanup;
-    }
+    if (!(handler = virLogHandlerPreExecRestart(logDaemon->handler)))
+        return -1;

+    if (virJSONValueObjectAppend(object, "handler", handler) < 0)
+        return -1;
+    handler = NULL;

     if (!(state = virJSONValueToString(object, true)))
-        goto cleanup;
+        return -1;

     VIR_DEBUG("Saving state %s", state);

-    if (virFileWriteStr(state_file,
-                        state, 0700) < 0) {
+    if (virFileWriteStr(state_file, state, 0700) < 0) {
         virReportSystemError(errno,
-                             _("Unable to save state file %s"),
-                             state_file);
-        goto cleanup;
+                             _("Unable to save state file %s"), state_file);
+        return -1;
     }

     if (execvp(argv[0], argv) < 0) {
         virReportSystemError(errno, "%s",
                              _("Unable to restart self"));
-        goto cleanup;
+        return -1;
     }

     abort(); /* This should be impossible to reach */

- cleanup:
-    VIR_FREE(magic);
-    VIR_FREE(state);
-    virJSONValueFree(object);
-    return -1;
+    return 0;
 }


-- 
2.29.2




[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