[PATCH 06/25] virNetServerClientPreExecRestart: Refactor memory cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/rpc/virnetserverclient.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 4d01e87e21..0789ad9154 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -585,15 +585,14 @@ virNetServerClientPtr virNetServerClientNewPostExecRestart(virNetServerPtr srv,

 virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
 {
-    virJSONValuePtr object = virJSONValueNewObject();
-    virJSONValuePtr child;
+    g_autoptr(virJSONValue) object = virJSONValueNewObject();
+    g_autoptr(virJSONValue) sock = NULL;
+    g_autoptr(virJSONValue) priv = NULL;

     virObjectLock(client);

-    if (virJSONValueObjectAppendNumberUlong(object, "id",
-                                            client->id) < 0)
+    if (virJSONValueObjectAppendNumberUlong(object, "id", client->id) < 0)
         goto error;
-
     if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
         goto error;
     if (virJSONValueObjectAppendBoolean(object, "auth_pending", client->auth_pending) < 0)
@@ -608,28 +607,25 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
                                            client->conn_time) < 0)
         goto error;

-    if (!(child = virNetSocketPreExecRestart(client->sock)))
+    if (!(sock = virNetSocketPreExecRestart(client->sock)))
         goto error;

-    if (virJSONValueObjectAppend(object, "sock", child) < 0) {
-        virJSONValueFree(child);
+    if (virJSONValueObjectAppend(object, "sock", sock) < 0)
         goto error;
-    }
+    sock = NULL;

-    if (!(child = client->privateDataPreExecRestart(client, client->privateData)))
+    if (!(priv = client->privateDataPreExecRestart(client, client->privateData)))
         goto error;

-    if (virJSONValueObjectAppend(object, "privateData", child) < 0) {
-        virJSONValueFree(child);
+    if (virJSONValueObjectAppend(object, "privateData", priv) < 0)
         goto error;
-    }
+    priv = NULL;

     virObjectUnlock(client);
-    return object;
+    return g_steal_pointer(&object);

  error:
     virObjectUnlock(client);
-    virJSONValueFree(object);
     return NULL;
 }

-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux