Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. --- tools/virsh-snapshot.c | 48 ++++++++++++++++++------------------------------ tools/virsh-util.c | 10 ++++++++++ tools/virsh-util.h | 3 +++ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 5af9a7d7a..24cd4abd9 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -106,8 +106,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, cleanup: xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); VIR_FREE(doc); return ret; } @@ -601,10 +600,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) cleanup: if (!ret && name) vshError(ctl, _("Failed to update %s"), name); - if (edited) - virDomainSnapshotFree(edited); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(edited); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; } @@ -681,7 +678,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!(snapshot2 = virDomainSnapshotCreateXML(dom, xml, flags))) goto cleanup; - virDomainSnapshotFree(snapshot2); + virshDomainSnapshotFree(snapshot2); vshPrintExtra(ctl, _("Snapshot %s set as current"), snapshotname); ret = true; goto cleanup; @@ -717,8 +714,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) if (!ret) vshReportError(ctl); VIR_FREE(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -777,8 +773,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot, } else { vshResetLibvirtError(); } - if (parent) - virDomainSnapshotFree(parent); + virshDomainSnapshotFree(parent); xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); VIR_FREE(xml); @@ -906,7 +901,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) if (other) { if (STREQ(name, virDomainSnapshotGetName(other))) current = 1; - virDomainSnapshotFree(other); + virshDomainSnapshotFree(other); } } vshPrint(ctl, "%-15s %s\n", _("Current:"), @@ -1005,8 +1000,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) xmlFreeDoc(xmldoc); VIR_FREE(doc); VIR_FREE(parent); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; } @@ -1031,8 +1025,7 @@ virshSnapshotListFree(virshSnapshotListPtr snaplist) return; if (snaplist->snaps) { for (i = 0; i < snaplist->nsnaps; i++) { - if (snaplist->snaps[i].snap) - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); VIR_FREE(snaplist->snaps[i].parent); } VIR_FREE(snaplist->snaps); @@ -1270,7 +1263,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, STRNEQ_NULLABLE(fromname, snaplist->snaps[i].parent)))) || (roots && snaplist->snaps[i].parent)) { - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap = NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1298,7 +1291,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, for (i = 0; i < count; i++) { if (i == start_index || !snaplist->snaps[i].parent) { VIR_FREE(names[i]); - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap = NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1336,7 +1329,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, if (!found_parent) { changed = true; VIR_FREE(names[i]); - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap = NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1359,7 +1352,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, case 1: break; case 0: - virDomainSnapshotFree(snaplist->snaps[i].snap); + virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap = NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; @@ -1641,8 +1634,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) virshSnapshotListFree(snaplist); VIR_FREE(parent_snap); VIR_FREE(state); - if (start) - virDomainSnapshotFree(start); + virshDomainSnapshotFree(start); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(doc); @@ -1708,8 +1700,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1768,8 +1759,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(parent); - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1853,8 +1843,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; @@ -1935,8 +1924,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - if (snapshot) - virDomainSnapshotFree(snapshot); + virshDomainSnapshotFree(snapshot); virshDomainFree(dom); return ret; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 5fdb40855..e225d3332 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -160,3 +160,13 @@ virshDomainFree(virDomainPtr dom) virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ } + + +void +virshDomainSnapshotFree(virDomainSnapshotPtr snap) +{ + if (!snap) + return; + + virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */ +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 78f7a0ea9..2b5aedfba 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl, void virshDomainFree(virDomainPtr dom); +void +virshDomainSnapshotFree(virDomainSnapshotPtr snap); + int virshDomainState(vshControl *ctl, virDomainPtr dom, -- 2.12.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list