]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: checkpoint: move variables inside the loop
authorJán Tomko <jtomko@redhat.com>
Tue, 10 Aug 2021 17:26:45 +0000 (19:26 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 11 Aug 2021 08:52:58 +0000 (10:52 +0200)
Use g_auto to free them instead of open-coding it.

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

index e88f9ffb474bf7bc2c95b9b3b506919cea736ef5..2b89f376c9b8fe4553805647f4e99ccdbd33fa3a 100644 (file)
@@ -716,9 +716,6 @@ cmdCheckpointList(vshControl *ctl,
     bool ret = false;
     unsigned int flags = 0;
     size_t i;
-    xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
-    char *doc = NULL;
     virDomainCheckpointPtr checkpoint = NULL;
     long long creation_longlong;
     g_autoptr(GDateTime) then = NULL;
@@ -728,7 +725,6 @@ cmdCheckpointList(vshControl *ctl,
     bool parent = vshCommandOptBool(cmd, "parent");
     bool roots = vshCommandOptBool(cmd, "roots");
     const char *from_chk = NULL;
-    char *parent_chk = NULL;
     virDomainCheckpointPtr start = NULL;
     struct virshCheckpointList *checkpointlist = NULL;
     vshTable *table = NULL;
@@ -805,14 +801,12 @@ cmdCheckpointList(vshControl *ctl,
 
     for (i = 0; i < checkpointlist->nchks; i++) {
         g_autofree gchar *thenstr = NULL;
+        g_autoptr(xmlDoc) xml = NULL;
+        g_autoptr(xmlXPathContext) ctxt = NULL;
+        g_autofree char *parent_chk = NULL;
+        g_autofree char *doc = NULL;
         const char *chk_name;
 
-        /* free up memory from previous iterations of the loop */
-        VIR_FREE(parent_chk);
-        xmlXPathFreeContext(ctxt);
-        xmlFreeDoc(xml);
-        VIR_FREE(doc);
-
         checkpoint = checkpointlist->chks[i].chk;
         chk_name = virDomainCheckpointGetName(checkpoint);
         assert(chk_name);
@@ -856,13 +850,8 @@ cmdCheckpointList(vshControl *ctl,
     ret = true;
 
  cleanup:
-    /* this frees up memory from the last iteration of the loop */
     virshCheckpointListFree(checkpointlist);
-    VIR_FREE(parent_chk);
     virshDomainCheckpointFree(start);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(xml);
-    VIR_FREE(doc);
     virshDomainFree(dom);
     vshTableFree(table);