]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuAgentGetHostname: Refactor to remove cleanup section
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 Mar 2020 09:55:22 +0000 (10:55 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Mar 2020 11:02:20 +0000 (12:02 +0100)
Use g_autoptr instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_agent.c

index 0a03bd7c2cb7410feed3ea84c516f713c5f74a9d..3a40084f309de7ac950948d4cc55bcf35ad6d316 100644 (file)
@@ -1720,44 +1720,36 @@ int
 qemuAgentGetHostname(qemuAgentPtr agent,
                      char **hostname)
 {
-    int ret = -1;
-    virJSONValuePtr cmd;
-    virJSONValuePtr reply = NULL;
+    g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-get-host-name", NULL);
+    g_autoptr(virJSONValue) reply = NULL;
     virJSONValuePtr data = NULL;
     const char *result = NULL;
 
-    cmd = qemuAgentMakeCommand("guest-get-host-name",
-                               NULL);
-
     if (!cmd)
-        return ret;
+        return -1;
 
     if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
-            ret = -2;
-        goto cleanup;
+            return -2;
+
+        return -1;
     }
 
     if (!(data = virJSONValueObjectGet(reply, "return"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("malformed return value"));
-        goto cleanup;
+        return -1;
     }
 
     if (!(result = virJSONValueObjectGetString(data, "host-name"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("'host-name' missing in guest-get-host-name reply"));
-        goto cleanup;
+        return -1;
     }
 
     *hostname = g_strdup(result);
 
-    ret = 0;
-
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(reply);
-    return ret;
+    return 0;
 }