mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
tools: virsh: use automatic cleanup for virDomainObj
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
7c0443fb73
commit
cf337df3d6
@ -32,7 +32,7 @@ virshCheckpointNameCompleter(vshControl *ctl,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControl *priv = ctl->privData;
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
virDomainCheckpointPtr *checkpoints = NULL;
|
||||
int ncheckpoints = 0;
|
||||
size_t i = 0;
|
||||
@ -60,7 +60,6 @@ virshCheckpointNameCompleter(vshControl *ctl,
|
||||
virshDomainCheckpointFree(checkpoints[i]);
|
||||
}
|
||||
g_free(checkpoints);
|
||||
virshDomainFree(dom);
|
||||
|
||||
return ret;
|
||||
|
||||
@ -71,6 +70,5 @@ virshCheckpointNameCompleter(vshControl *ctl,
|
||||
for (i = 0; i < ncheckpoints; i++)
|
||||
g_free(ret[i]);
|
||||
g_free(ret);
|
||||
virshDomainFree(dom);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
size_t niothreads = 0;
|
||||
g_autofree virDomainIOThreadInfoPtr *info = NULL;
|
||||
size_t i;
|
||||
@ -468,7 +468,6 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -478,7 +477,7 @@ virshDomainVcpuCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
xmlDocPtr xml = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
int nvcpus = 0;
|
||||
@ -509,7 +508,6 @@ virshDomainVcpuCompleter(vshControl *ctl,
|
||||
cleanup:
|
||||
xmlXPathFreeContext(ctxt);
|
||||
xmlFreeDoc(xml);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -519,7 +517,7 @@ virshDomainVcpulistCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
xmlDocPtr xml = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
int nvcpus = 0;
|
||||
@ -554,7 +552,6 @@ virshDomainVcpulistCompleter(vshControl *ctl,
|
||||
cleanup:
|
||||
xmlXPathFreeContext(ctxt);
|
||||
xmlFreeDoc(xml);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -594,7 +591,7 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
bool enable = vshCommandOptBool(cmd, "enable");
|
||||
bool disable = vshCommandOptBool(cmd, "disable");
|
||||
virTypedParameterPtr params = NULL;
|
||||
@ -690,7 +687,6 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
|
||||
|
||||
cleanup:
|
||||
virTypedParamsFree(params, nparams);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -908,7 +904,7 @@ virshDomainFSMountpointsCompleter(vshControl *ctl,
|
||||
unsigned int flags)
|
||||
{
|
||||
g_auto(GStrv) tmp = NULL;
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
int rc = -1;
|
||||
size_t i;
|
||||
virDomainFSInfoPtr *info = NULL;
|
||||
@ -938,7 +934,6 @@ virshDomainFSMountpointsCompleter(vshControl *ctl,
|
||||
virDomainFSInfoFree(info[i]);
|
||||
VIR_FREE(info);
|
||||
}
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ virshSnapshotNameCompleter(vshControl *ctl,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControl *priv = ctl->privData;
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
virDomainSnapshotPtr *snapshots = NULL;
|
||||
int rc;
|
||||
int nsnapshots = 0;
|
||||
@ -63,7 +63,6 @@ virshSnapshotNameCompleter(vshControl *ctl,
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
for (i = 0; i < nsnapshots; i++)
|
||||
virshDomainSnapshotFree(snapshots[i]);
|
||||
g_free(snapshots);
|
||||
|
@ -296,7 +296,7 @@ static const vshCmdOptDef opts_dommemstat[] = {
|
||||
static bool
|
||||
cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *name;
|
||||
virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
|
||||
unsigned int nr_stats;
|
||||
@ -381,7 +381,6 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -893,7 +892,7 @@ static const vshCmdOptDef opts_domcontrol[] = {
|
||||
static bool
|
||||
cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
bool ret = true;
|
||||
virDomainControlInfo info;
|
||||
|
||||
@ -920,7 +919,6 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -994,7 +992,7 @@ static const struct _domblkstat_sequence domblkstat_output[] = {
|
||||
static bool
|
||||
cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *name = NULL, *device = NULL;
|
||||
virDomainBlockStatsStruct stats;
|
||||
virTypedParameterPtr params = NULL;
|
||||
@ -1106,7 +1104,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(params);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
#undef DOMBLKSTAT_LEGACY_PRINT
|
||||
@ -1138,7 +1135,7 @@ static const vshCmdOptDef opts_domifstat[] = {
|
||||
static bool
|
||||
cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *name = NULL, *device = NULL;
|
||||
virDomainInterfaceStatsStruct stats;
|
||||
bool ret = false;
|
||||
@ -1181,7 +1178,6 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1206,7 +1202,7 @@ static const vshCmdOptDef opts_domblkerror[] = {
|
||||
static bool
|
||||
cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
virDomainDiskErrorPtr disks = NULL;
|
||||
unsigned int ndisks = 0;
|
||||
size_t i;
|
||||
@ -1243,7 +1239,6 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
||||
for (i = 0; i < ndisks; i++)
|
||||
VIR_FREE(disks[i].disk);
|
||||
VIR_FREE(disks);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1269,7 +1264,7 @@ static bool
|
||||
cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainInfo info;
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
virSecurityModel secmodel;
|
||||
virSecurityLabelPtr seclabel;
|
||||
int persistent = 0;
|
||||
@ -1352,7 +1347,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
memset(&secmodel, 0, sizeof(secmodel));
|
||||
if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) {
|
||||
if (last_error->code != VIR_ERR_NO_SUPPORT) {
|
||||
virshDomainFree(dom);
|
||||
return false;
|
||||
} else {
|
||||
vshResetLibvirtError();
|
||||
@ -1367,7 +1361,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
seclabel = g_new0(virSecurityLabel, 1);
|
||||
|
||||
if (virDomainGetSecurityLabel(dom, seclabel) == -1) {
|
||||
virshDomainFree(dom);
|
||||
VIR_FREE(seclabel);
|
||||
return false;
|
||||
} else {
|
||||
@ -1388,7 +1381,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1417,7 +1409,7 @@ static const vshCmdOptDef opts_domstate[] = {
|
||||
static bool
|
||||
cmdDomstate(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
bool ret = true;
|
||||
bool showReason = vshCommandOptBool(cmd, "reason");
|
||||
int state, reason;
|
||||
@ -1440,7 +1432,6 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1481,7 +1472,7 @@ static const vshCmdOptDef opts_domtime[] = {
|
||||
static bool
|
||||
cmdDomTime(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
bool ret = false;
|
||||
bool now = vshCommandOptBool(cmd, "now");
|
||||
bool pretty = vshCommandOptBool(cmd, "pretty");
|
||||
@ -1540,7 +1531,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2373,7 +2363,7 @@ VIR_ENUM_IMPL(virshDomainInterfaceAddressesSource,
|
||||
static bool
|
||||
cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *ifacestr = NULL;
|
||||
virDomainInterfacePtr *ifaces = NULL;
|
||||
size_t i, j;
|
||||
@ -2466,7 +2456,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
VIR_FREE(ifaces);
|
||||
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user