]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: refactor qemuMonitorTestProcessCommandDefault
authorJán Tomko <jtomko@redhat.com>
Sat, 15 Jun 2019 09:43:09 +0000 (11:43 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 17 Jun 2019 14:12:57 +0000 (16:12 +0200)
Use VIR_AUTOPTR and get rid of the 'ret' variable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
tests/qemumonitortestutils.c

index 691111cbacb3865e26aed78151d87746881e0e8f..a038a420caa434319510166d508a1faaade8b498 100644 (file)
@@ -584,38 +584,29 @@ qemuMonitorTestProcessCommandDefault(qemuMonitorTestPtr test,
                                      const char *cmdstr)
 {
     struct qemuMonitorTestHandlerData *data = item->opaque;
-    virJSONValuePtr val = NULL;
+    VIR_AUTOPTR(virJSONValue) val = NULL;
     virJSONValuePtr cmdargs = NULL;
     const char *cmdname;
-    int ret = -1;
     int rc;
 
     if (!(val = virJSONValueFromString(cmdstr)))
         return -1;
 
-    if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) {
-        ret = qemuMonitorReportError(test, "Missing command name in %s", cmdstr);
-        goto cleanup;
-    }
+    if (!(cmdname = virJSONValueObjectGetString(val, "execute")))
+        return qemuMonitorReportError(test, "Missing command name in %s", cmdstr);
 
     cmdargs = virJSONValueObjectGet(val, "arguments");
     if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0)
-        goto cleanup;
+        return -1;
+    if (rc == 1)
+        return 0;
 
-    if (rc == 1) {
-        ret = 0;
-        goto cleanup;
+    if (data->command_name && STRNEQ(data->command_name, cmdname)) {
+        return qemuMonitorTestAddInvalidCommandResponse(test, data->command_name,
+                                                        cmdname);
+    } else {
+        return qemuMonitorTestAddResponse(test, data->response);
     }
-
-    if (data->command_name && STRNEQ(data->command_name, cmdname))
-        ret = qemuMonitorTestAddInvalidCommandResponse(test, data->command_name,
-                                                       cmdname);
-    else
-        ret = qemuMonitorTestAddResponse(test, data->response);
-
- cleanup:
-    virJSONValueFree(val);
-    return ret;
 }