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

index ab8dafb1bb66a93d9c27bdcc7609a2d23f06d7ef..ee402e8ea0ce4ba31199e757877c0a47b6a1ac74 100644 (file)
@@ -548,9 +548,9 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
 
 virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
 {
-    virJSONValuePtr object = virJSONValueNewObject();
-    virJSONValuePtr clients;
-    virJSONValuePtr services;
+    g_autoptr(virJSONValue) object = virJSONValueNewObject();
+    g_autoptr(virJSONValue) clients = virJSONValueNewArray();
+    g_autoptr(virJSONValue) services = virJSONValueNewArray();
     size_t i;
 
     virObjectLock(srv);
@@ -580,48 +580,39 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
                                             srv->next_client_id) < 0)
         goto error;
 
-    services = virJSONValueNewArray();
-
-    if (virJSONValueObjectAppend(object, "services", services) < 0) {
-        virJSONValueFree(services);
-        goto error;
-    }
-
     for (i = 0; i < srv->nservices; i++) {
-        virJSONValuePtr child;
+        g_autoptr(virJSONValue) child = NULL;
         if (!(child = virNetServerServicePreExecRestart(srv->services[i])))
             goto error;
 
-        if (virJSONValueArrayAppend(services, child) < 0) {
-            virJSONValueFree(child);
+        if (virJSONValueArrayAppend(services, child) < 0)
             goto error;
-        }
+        child = NULL;
     }
 
-    clients = virJSONValueNewArray();
-
-    if (virJSONValueObjectAppend(object, "clients", clients) < 0) {
-        virJSONValueFree(clients);
+    if (virJSONValueObjectAppend(object, "services", services) < 0)
         goto error;
-    }
+    services = NULL;
 
     for (i = 0; i < srv->nclients; i++) {
-        virJSONValuePtr child;
+        g_autoptr(virJSONValue) child = NULL;
         if (!(child = virNetServerClientPreExecRestart(srv->clients[i])))
             goto error;
 
-        if (virJSONValueArrayAppend(clients, child) < 0) {
-            virJSONValueFree(child);
+        if (virJSONValueArrayAppend(clients, child) < 0)
             goto error;
-        }
+        child = NULL;
     }
 
+    if (virJSONValueObjectAppend(object, "clients", clients) < 0)
+        goto error;
+    clients = NULL;
+
     virObjectUnlock(srv);
 
-    return object;
+    return g_steal_pointer(&object);
 
  error:
-    virJSONValueFree(object);
     virObjectUnlock(srv);
     return NULL;
 }