]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentMakeStringsArray: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Fri, 12 Feb 2021 10:32:46 +0000 (11:32 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Sat, 20 Feb 2021 12:26:37 +0000 (13:26 +0100)
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_agent.c

index 4712aeb529bffe14722886060dcd6b7eb3a69794..d6816ef9dede546c603a9cbe2067b6a204b4e6eb 100644 (file)
@@ -1175,23 +1175,17 @@ static virJSONValuePtr
 qemuAgentMakeStringsArray(const char **strings, unsigned int len)
 {
     size_t i;
-    virJSONValuePtr ret = virJSONValueNewArray(), str;
+    g_autoptr(virJSONValue) ret = virJSONValueNewArray();
 
     for (i = 0; i < len; i++) {
-        str = virJSONValueNewString(strings[i]);
-        if (!str)
-            goto error;
+        g_autoptr(virJSONValue) str = virJSONValueNewString(strings[i]);
 
-        if (virJSONValueArrayAppend(ret, str) < 0) {
-            virJSONValueFree(str);
-            goto error;
-        }
+        if (virJSONValueArrayAppend(ret, str) < 0)
+            return NULL;
+        str = NULL;
     }
-    return ret;
 
- error:
-    virJSONValueFree(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 void qemuAgentNotifyEvent(qemuAgentPtr agent,