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:
Ján Tomko 2021-08-11 11:33:50 +02:00
parent 7c0443fb73
commit cf337df3d6
5 changed files with 116 additions and 238 deletions

View File

@ -32,7 +32,7 @@ virshCheckpointNameCompleter(vshControl *ctl,
unsigned int flags) unsigned int flags)
{ {
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
virDomainCheckpointPtr *checkpoints = NULL; virDomainCheckpointPtr *checkpoints = NULL;
int ncheckpoints = 0; int ncheckpoints = 0;
size_t i = 0; size_t i = 0;
@ -60,7 +60,6 @@ virshCheckpointNameCompleter(vshControl *ctl,
virshDomainCheckpointFree(checkpoints[i]); virshDomainCheckpointFree(checkpoints[i]);
} }
g_free(checkpoints); g_free(checkpoints);
virshDomainFree(dom);
return ret; return ret;
@ -71,6 +70,5 @@ virshCheckpointNameCompleter(vshControl *ctl,
for (i = 0; i < ncheckpoints; i++) for (i = 0; i < ncheckpoints; i++)
g_free(ret[i]); g_free(ret[i]);
g_free(ret); g_free(ret);
virshDomainFree(dom);
return NULL; return NULL;
} }

View File

@ -442,7 +442,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags) unsigned int flags)
{ {
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
size_t niothreads = 0; size_t niothreads = 0;
g_autofree virDomainIOThreadInfoPtr *info = NULL; g_autofree virDomainIOThreadInfoPtr *info = NULL;
size_t i; size_t i;
@ -468,7 +468,6 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
ret = g_steal_pointer(&tmp); ret = g_steal_pointer(&tmp);
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -478,7 +477,7 @@ virshDomainVcpuCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags) unsigned int flags)
{ {
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
int nvcpus = 0; int nvcpus = 0;
@ -509,7 +508,6 @@ virshDomainVcpuCompleter(vshControl *ctl,
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
virshDomainFree(dom);
return ret; return ret;
} }
@ -519,7 +517,7 @@ virshDomainVcpulistCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags) unsigned int flags)
{ {
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
int nvcpus = 0; int nvcpus = 0;
@ -554,7 +552,6 @@ virshDomainVcpulistCompleter(vshControl *ctl,
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
virshDomainFree(dom);
return ret; return ret;
} }
@ -594,7 +591,7 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags) unsigned int flags)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
bool enable = vshCommandOptBool(cmd, "enable"); bool enable = vshCommandOptBool(cmd, "enable");
bool disable = vshCommandOptBool(cmd, "disable"); bool disable = vshCommandOptBool(cmd, "disable");
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
@ -690,7 +687,6 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
cleanup: cleanup:
virTypedParamsFree(params, nparams); virTypedParamsFree(params, nparams);
virshDomainFree(dom);
return ret; return ret;
} }
@ -908,7 +904,7 @@ virshDomainFSMountpointsCompleter(vshControl *ctl,
unsigned int flags) unsigned int flags)
{ {
g_auto(GStrv) tmp = NULL; g_auto(GStrv) tmp = NULL;
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
int rc = -1; int rc = -1;
size_t i; size_t i;
virDomainFSInfoPtr *info = NULL; virDomainFSInfoPtr *info = NULL;
@ -938,7 +934,6 @@ virshDomainFSMountpointsCompleter(vshControl *ctl,
virDomainFSInfoFree(info[i]); virDomainFSInfoFree(info[i]);
VIR_FREE(info); VIR_FREE(info);
} }
virshDomainFree(dom);
return ret; return ret;
} }

View File

@ -32,7 +32,7 @@ virshSnapshotNameCompleter(vshControl *ctl,
unsigned int flags) unsigned int flags)
{ {
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
virDomainSnapshotPtr *snapshots = NULL; virDomainSnapshotPtr *snapshots = NULL;
int rc; int rc;
int nsnapshots = 0; int nsnapshots = 0;
@ -63,7 +63,6 @@ virshSnapshotNameCompleter(vshControl *ctl,
ret = g_steal_pointer(&tmp); ret = g_steal_pointer(&tmp);
cleanup: cleanup:
virshDomainFree(dom);
for (i = 0; i < nsnapshots; i++) for (i = 0; i < nsnapshots; i++)
virshDomainSnapshotFree(snapshots[i]); virshDomainSnapshotFree(snapshots[i]);
g_free(snapshots); g_free(snapshots);

View File

@ -296,7 +296,7 @@ static const vshCmdOptDef opts_dommemstat[] = {
static bool static bool
cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
const char *name; const char *name;
virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
unsigned int nr_stats; unsigned int nr_stats;
@ -381,7 +381,6 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -893,7 +892,7 @@ static const vshCmdOptDef opts_domcontrol[] = {
static bool static bool
cmdDomControl(vshControl *ctl, const vshCmd *cmd) cmdDomControl(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
bool ret = true; bool ret = true;
virDomainControlInfo info; virDomainControlInfo info;
@ -920,7 +919,6 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -994,7 +992,7 @@ static const struct _domblkstat_sequence domblkstat_output[] = {
static bool static bool
cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
const char *name = NULL, *device = NULL; const char *name = NULL, *device = NULL;
virDomainBlockStatsStruct stats; virDomainBlockStatsStruct stats;
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
@ -1106,7 +1104,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_FREE(params); VIR_FREE(params);
virshDomainFree(dom);
return ret; return ret;
} }
#undef DOMBLKSTAT_LEGACY_PRINT #undef DOMBLKSTAT_LEGACY_PRINT
@ -1138,7 +1135,7 @@ static const vshCmdOptDef opts_domifstat[] = {
static bool static bool
cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
const char *name = NULL, *device = NULL; const char *name = NULL, *device = NULL;
virDomainInterfaceStatsStruct stats; virDomainInterfaceStatsStruct stats;
bool ret = false; bool ret = false;
@ -1181,7 +1178,6 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -1206,7 +1202,7 @@ static const vshCmdOptDef opts_domblkerror[] = {
static bool static bool
cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
virDomainDiskErrorPtr disks = NULL; virDomainDiskErrorPtr disks = NULL;
unsigned int ndisks = 0; unsigned int ndisks = 0;
size_t i; size_t i;
@ -1243,7 +1239,6 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < ndisks; i++) for (i = 0; i < ndisks; i++)
VIR_FREE(disks[i].disk); VIR_FREE(disks[i].disk);
VIR_FREE(disks); VIR_FREE(disks);
virshDomainFree(dom);
return ret; return ret;
} }
@ -1269,7 +1264,7 @@ static bool
cmdDominfo(vshControl *ctl, const vshCmd *cmd) cmdDominfo(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainInfo info; virDomainInfo info;
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
virSecurityModel secmodel; virSecurityModel secmodel;
virSecurityLabelPtr seclabel; virSecurityLabelPtr seclabel;
int persistent = 0; int persistent = 0;
@ -1352,7 +1347,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
memset(&secmodel, 0, sizeof(secmodel)); memset(&secmodel, 0, sizeof(secmodel));
if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) { if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) {
if (last_error->code != VIR_ERR_NO_SUPPORT) { if (last_error->code != VIR_ERR_NO_SUPPORT) {
virshDomainFree(dom);
return false; return false;
} else { } else {
vshResetLibvirtError(); vshResetLibvirtError();
@ -1367,7 +1361,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
seclabel = g_new0(virSecurityLabel, 1); seclabel = g_new0(virSecurityLabel, 1);
if (virDomainGetSecurityLabel(dom, seclabel) == -1) { if (virDomainGetSecurityLabel(dom, seclabel) == -1) {
virshDomainFree(dom);
VIR_FREE(seclabel); VIR_FREE(seclabel);
return false; return false;
} else { } else {
@ -1388,7 +1381,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
} }
} }
virshDomainFree(dom);
return ret; return ret;
} }
@ -1417,7 +1409,7 @@ static const vshCmdOptDef opts_domstate[] = {
static bool static bool
cmdDomstate(vshControl *ctl, const vshCmd *cmd) cmdDomstate(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
bool ret = true; bool ret = true;
bool showReason = vshCommandOptBool(cmd, "reason"); bool showReason = vshCommandOptBool(cmd, "reason");
int state, reason; int state, reason;
@ -1440,7 +1432,6 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -1481,7 +1472,7 @@ static const vshCmdOptDef opts_domtime[] = {
static bool static bool
cmdDomTime(vshControl *ctl, const vshCmd *cmd) cmdDomTime(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom; g_autoptr(virshDomain) dom = NULL;
bool ret = false; bool ret = false;
bool now = vshCommandOptBool(cmd, "now"); bool now = vshCommandOptBool(cmd, "now");
bool pretty = vshCommandOptBool(cmd, "pretty"); bool pretty = vshCommandOptBool(cmd, "pretty");
@ -1540,7 +1531,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
virshDomainFree(dom);
return ret; return ret;
} }
@ -2373,7 +2363,7 @@ VIR_ENUM_IMPL(virshDomainInterfaceAddressesSource,
static bool static bool
cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainPtr dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *ifacestr = NULL; const char *ifacestr = NULL;
virDomainInterfacePtr *ifaces = NULL; virDomainInterfacePtr *ifaces = NULL;
size_t i, j; size_t i, j;
@ -2466,7 +2456,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
} }
VIR_FREE(ifaces); VIR_FREE(ifaces);
virshDomainFree(dom);
return ret; return ret;
} }

File diff suppressed because it is too large Load Diff