mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: snapshot: move variables inside the loop
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>
This commit is contained in:
parent
7f1c6736fa
commit
56bb594532
@ -1490,11 +1490,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
xmlDocPtr xml = NULL;
|
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
char *doc = NULL;
|
|
||||||
virDomainSnapshotPtr snapshot = NULL;
|
virDomainSnapshotPtr snapshot = NULL;
|
||||||
char *state = NULL;
|
|
||||||
long long creation_longlong;
|
long long creation_longlong;
|
||||||
g_autoptr(GDateTime) then = NULL;
|
g_autoptr(GDateTime) then = NULL;
|
||||||
bool tree = vshCommandOptBool(cmd, "tree");
|
bool tree = vshCommandOptBool(cmd, "tree");
|
||||||
@ -1504,7 +1500,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool roots = vshCommandOptBool(cmd, "roots");
|
bool roots = vshCommandOptBool(cmd, "roots");
|
||||||
bool current = vshCommandOptBool(cmd, "current");
|
bool current = vshCommandOptBool(cmd, "current");
|
||||||
const char *from_snap = NULL;
|
const char *from_snap = NULL;
|
||||||
char *parent_snap = NULL;
|
|
||||||
virDomainSnapshotPtr start = NULL;
|
virDomainSnapshotPtr start = NULL;
|
||||||
struct virshSnapshotList *snaplist = NULL;
|
struct virshSnapshotList *snaplist = NULL;
|
||||||
vshTable *table = NULL;
|
vshTable *table = NULL;
|
||||||
@ -1592,15 +1587,13 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
for (i = 0; i < snaplist->nsnaps; i++) {
|
for (i = 0; i < snaplist->nsnaps; i++) {
|
||||||
g_autofree gchar *thenstr = NULL;
|
g_autofree gchar *thenstr = NULL;
|
||||||
|
g_autoptr(xmlDoc) xml = NULL;
|
||||||
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||||
|
g_autofree char *parent_snap = NULL;
|
||||||
|
g_autofree char *state = NULL;
|
||||||
|
g_autofree char *doc = NULL;
|
||||||
const char *snap_name;
|
const char *snap_name;
|
||||||
|
|
||||||
/* free up memory from previous iterations of the loop */
|
|
||||||
VIR_FREE(parent_snap);
|
|
||||||
VIR_FREE(state);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
|
||||||
VIR_FREE(doc);
|
|
||||||
|
|
||||||
snapshot = snaplist->snaps[i].snap;
|
snapshot = snaplist->snaps[i].snap;
|
||||||
snap_name = virDomainSnapshotGetName(snapshot);
|
snap_name = virDomainSnapshotGetName(snapshot);
|
||||||
assert(snap_name);
|
assert(snap_name);
|
||||||
@ -1648,14 +1641,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
/* this frees up memory from the last iteration of the loop */
|
|
||||||
virshSnapshotListFree(snaplist);
|
virshSnapshotListFree(snaplist);
|
||||||
VIR_FREE(parent_snap);
|
|
||||||
VIR_FREE(state);
|
|
||||||
virshDomainSnapshotFree(start);
|
virshDomainSnapshotFree(start);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
|
||||||
VIR_FREE(doc);
|
|
||||||
virshDomainFree(dom);
|
virshDomainFree(dom);
|
||||||
vshTableFree(table);
|
vshTableFree(table);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user