]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()
authorPavel Mores <pmores@redhat.com>
Fri, 6 Dec 2019 09:11:28 +0000 (10:11 +0100)
committerCole Robinson <crobinso@redhat.com>
Tue, 17 Dec 2019 15:49:30 +0000 (10:49 -0500)
While at bugfixing, convert the whole function to the new-style memory
allocation handling.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Mores <pmores@redhat.com>
src/qemu/qemu_monitor_text.c

index 70ecd2281b60431bd34f76cfc0ed8ebad2b6576c..9135a11f0a3aae718c86bb199112fba8d16d4d80 100644 (file)
@@ -132,14 +132,13 @@ int
 qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
                               const char *name)
 {
-    char *cmd = NULL;
-    char *reply = NULL;
-    int ret = -1;
+    g_autofree char *cmd = NULL;
+    g_autofree char *reply = NULL;
 
     cmd = g_strdup_printf("savevm \"%s\"", name);
 
     if (qemuMonitorJSONHumanCommand(mon, cmd, &reply))
-        goto cleanup;
+        return -1;
 
     if (strstr(reply, "Error while creating snapshot") ||
         strstr(reply, "Could not open VM state file") ||
@@ -148,19 +147,14 @@ qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
         (strstr(reply, "Error") && strstr(reply, "while writing VM"))) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("Failed to take snapshot: %s"), reply);
-        goto cleanup;
+        return -1;
     } else if (strstr(reply, "No block device can accept snapshots")) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("this domain does not have a device to take snapshots"));
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    VIR_FREE(cmd);
-    VIR_FREE(reply);
-    return ret;
+    return 0;
 }
 
 int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name)