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

index 51cc00c618192abae87f76695573407ec0025a06..4712aeb529bffe14722886060dcd6b7eb3a69794 100644 (file)
@@ -1149,31 +1149,26 @@ static virJSONValuePtr G_GNUC_NULL_TERMINATED
 qemuAgentMakeCommand(const char *cmdname,
                      ...)
 {
-    virJSONValuePtr obj = virJSONValueNewObject();
-    virJSONValuePtr jargs = NULL;
+    g_autoptr(virJSONValue) obj = NULL;
+    g_autoptr(virJSONValue) jargs = NULL;
     va_list args;
 
     va_start(args, cmdname);
 
-    if (virJSONValueObjectAppendString(obj, "execute", cmdname) < 0)
-        goto error;
-
-    if (virJSONValueObjectCreateVArgs(&jargs, args) < 0)
-        goto error;
-
-    if (jargs &&
-        virJSONValueObjectAppend(obj, "arguments", jargs) < 0)
-        goto error;
+    if (virJSONValueObjectCreateVArgs(&jargs, args) < 0) {
+        va_end(args);
+        return NULL;
+    }
 
     va_end(args);
 
-    return obj;
+    if (virJSONValueObjectCreate(&obj,
+                                 "s:execute", cmdname,
+                                 "A:arguments", &jargs,
+                                 NULL) < 0)
+        return NULL;
 
- error:
-    virJSONValueFree(obj);
-    virJSONValueFree(jargs);
-    va_end(args);
-    return NULL;
+    return g_steal_pointer(&obj);
 }
 
 static virJSONValuePtr