[libvirt] [PATCH 2/3] qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()

Pavel Mores posted 3 patches 6 years, 2 months ago
[libvirt] [PATCH 2/3] qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()
Posted by Pavel Mores 6 years, 2 months ago
While at bugfixing, convert the whole function to the new-style memory
allocation handling.

Signed-off-by: Pavel Mores <pmores@redhat.com>
---
 src/qemu/qemu_monitor_text.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index b387235821..7586ba4c54 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -125,14 +125,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") ||
@@ -141,19 +140,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)
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/3] qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()
Posted by Cole Robinson 6 years, 1 month ago
On 12/6/19 4:11 AM, Pavel Mores wrote:
> While at bugfixing, convert the whole function to the new-style memory
> allocation handling.
> 
> Signed-off-by: Pavel Mores <pmores@redhat.com>
> ---
>  src/qemu/qemu_monitor_text.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 

Reviewed-by: Cole Robinson <crobinso@redhat.com>

Looks like this patch was missed. Pushed now

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/3] qemu: use g_autofree instead of VIR_FREE in qemuMonitorTextCreateSnapshot()
Posted by Pavel Mores 6 years, 1 month ago
On Tue, Dec 17, 2019 at 10:55:24AM -0500, Cole Robinson wrote:
> On 12/6/19 4:11 AM, Pavel Mores wrote:
> > While at bugfixing, convert the whole function to the new-style memory
> > allocation handling.
> > 
> > Signed-off-by: Pavel Mores <pmores@redhat.com>
> > ---
> >  src/qemu/qemu_monitor_text.c | 18 ++++++------------
> >  1 file changed, 6 insertions(+), 12 deletions(-)
> > 
> 
> Reviewed-by: Cole Robinson <crobinso@redhat.com>
> 
> Looks like this patch was missed. Pushed now

Thanks!  I dropped this patch from v2 intentionally because it was just a
clean-up of a previous patch which was dropped (for duplicating a recent
commit) and without which this one felt out of place and context in v2.

But on its own, this patch is still relevant so it's good you pushed it.

Thanks,

	pvl

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list