]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuMonitorTestAddItemVerbatim: Simplify cleanup
authorPeter Krempa <pkrempa@redhat.com>
Mon, 22 May 2023 12:05:46 +0000 (14:05 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Jun 2023 07:41:25 +0000 (09:41 +0200)
Reformat the JSON string before allocating the test data structure so
that we don't have to free it if the reformatting fails.

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

index 4e99c4b54e583e0007ca3925ef5dd11142d7fef1..cfe78b258a400533443bae78ff6439905275903b 100644 (file)
@@ -673,24 +673,21 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test,
                                const char *response)
 {
     struct qemuMonitorTestHandlerData *data;
+    char *reformatted = NULL;
+
+    if (!(reformatted = virJSONStringReformat(command, false)))
+        return -1;
 
     data = g_new0(struct qemuMonitorTestHandlerData, 1);
 
     data->response = g_strdup(response);
     data->cmderr = g_strdup(cmderr);
-
-    data->command_name = virJSONStringReformat(command, false);
-    if (!data->command_name)
-        goto error;
+    data->command_name = g_steal_pointer(&reformatted);
 
     return qemuMonitorTestAddHandler(test,
                                      command,
                                      qemuMonitorTestProcessCommandVerbatim,
                                      data, qemuMonitorTestHandlerDataFree);
-
- error:
-    qemuMonitorTestHandlerDataFree(data);
-    return -1;
 }