]> xenbits.xensource.com Git - libvirt.git/commitdiff
virLogHandlerPreExecRestart: 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_handler.c

index a77c1e02502c428d0179c7ab35664c61ef083cc0..cacf9584cdfd9529f2cef0e655e679c6489276de 100644 (file)
@@ -608,56 +608,48 @@ virLogHandlerDomainAppendLogFile(virLogHandlerPtr handler,
 virJSONValuePtr
 virLogHandlerPreExecRestart(virLogHandlerPtr handler)
 {
-    virJSONValuePtr ret = virJSONValueNewObject();
-    virJSONValuePtr files;
+    g_autoptr(virJSONValue) ret = virJSONValueNewObject();
+    g_autoptr(virJSONValue) files = virJSONValueNewArray();
     size_t i;
     char domuuid[VIR_UUID_STRING_BUFLEN];
 
-    files = virJSONValueNewArray();
-
-    if (virJSONValueObjectAppend(ret, "files", files) < 0) {
-        virJSONValueFree(files);
-        goto error;
-    }
-
     for (i = 0; i < handler->nfiles; i++) {
-        virJSONValuePtr file = virJSONValueNewObject();
-
-        if (virJSONValueArrayAppend(files, file) < 0) {
-            virJSONValueFree(file);
-            goto error;
-        }
+        g_autoptr(virJSONValue) file = virJSONValueNewObject();
 
         if (virJSONValueObjectAppendNumberInt(file, "pipefd",
                                               handler->files[i]->pipefd) < 0)
-            goto error;
+            return NULL;
 
         if (virJSONValueObjectAppendString(file, "path",
                                            virRotatingFileWriterGetPath(handler->files[i]->file)) < 0)
-            goto error;
+            return NULL;
 
         if (virJSONValueObjectAppendString(file, "driver",
                                            handler->files[i]->driver) < 0)
-            goto error;
+            return NULL;
 
         if (virJSONValueObjectAppendString(file, "domname",
                                            handler->files[i]->domname) < 0)
-            goto error;
+            return NULL;
 
         virUUIDFormat(handler->files[i]->domuuid, domuuid);
         if (virJSONValueObjectAppendString(file, "domuuid", domuuid) < 0)
-            goto error;
+            return NULL;
 
         if (virSetInherit(handler->files[i]->pipefd, true) < 0) {
             virReportSystemError(errno, "%s",
                                  _("Cannot disable close-on-exec flag"));
-            goto error;
+            return NULL;
         }
+
+        if (virJSONValueArrayAppend(files, file) < 0)
+            return NULL;
+        file = NULL;
     }
 
-    return ret;
+    if (virJSONValueObjectAppend(ret, "files", files) < 0)
+        return NULL;
+    files = NULL;
 
- error:
-    virJSONValueFree(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }