]> xenbits.xensource.com Git - libvirt.git/commitdiff
virLogDaemonPreExecRestart: Refactor memory cleanup
authorPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Sat, 20 Feb 2021 12:26:36 +0000 (13:26 +0100)
Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/logging/log_daemon.c

index 770f6dd273ca7484f908e0bc73d2d57e041b7c72..ceffa6a3689a3a47e5b1458b26a024e883095513 100644 (file)
@@ -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;
 }