[libvirt PATCH 00/12] tools: virsh: use g_auto more (glib chronicles)

Incomprehensive series removing many cleanup sections. Patch 1/12 is common with my other series: [libvirt PATCH 0/3] xml: use g_auto for xmlXPathObject Ján Tomko (12): util: define cleanup func for xmlXPathObject tools: virsh: split variable declarations tools: virsh: cmdDominfo: rename 'ostype' variable tools: virsh: use automatic cleanup for virDomainObj tools: virsh: use automatic cleanup for xmlXPathContext tools: virsh: use automatic cleanup for xmlXPathObject tools: virsh: use automatic cleanup for xmlDoc tools: virsh: use automatic cleanup for vshTable tools: virsh: reduce variable scope to use automatic cleanup tools: virsh: use automatic cleanup for char ** tools: virsh: use g_autofree tools: virsh: remove redundant labels src/util/virxml.h | 1 + tools/virsh-completer-checkpoint.c | 4 +- tools/virsh-completer-domain.c | 57 +- tools/virsh-completer-snapshot.c | 3 +- tools/virsh-domain-monitor.c | 256 ++---- tools/virsh-domain.c | 1225 ++++++++++------------------ tools/virsh-host.c | 212 ++--- tools/virsh-interface.c | 21 +- tools/virsh-network.c | 24 +- tools/virsh-nodedev.c | 27 +- tools/virsh-nwfilter.c | 15 +- tools/virsh-pool.c | 34 +- tools/virsh-secret.c | 9 +- tools/virsh-util.c | 3 +- tools/virsh-volume.c | 35 +- tools/virsh.c | 3 +- tools/virt-admin.c | 6 +- tools/vsh.c | 11 +- 18 files changed, 660 insertions(+), 1286 deletions(-) -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virxml.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virxml.h b/src/util/virxml.h index 0bb0d1c118..c8eb51a65a 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -363,6 +363,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, virXPathContextNodeRes G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlDoc, xmlFreeDoc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathContext, xmlXPathFreeContext); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlXPathObject, xmlXPathFreeObject); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlBuffer, xmlBufferFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlNode, xmlFreeNode); G_DEFINE_AUTOPTR_CLEANUP_FUNC(xmlParserCtxt, xmlFreeParserCtxt); -- 2.31.1

One variable per line. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 81f3c82094..ae979ddd49 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5912,7 +5912,8 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) const char *mode = NULL; int flags = 0; int rv; - char **modes = NULL, **tmp; + char **modes = NULL; + char **tmp; if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) return false; @@ -5996,7 +5997,8 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) const char *name; const char *mode = NULL; int flags = 0; - char **modes = NULL, **tmp; + char **modes = NULL; + char **tmp; if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) return false; @@ -12166,7 +12168,8 @@ virshDomainDetachInterface(char *doc, xmlXPathObjectPtr obj = NULL; xmlXPathContextPtr ctxt = NULL; xmlNodePtr cur = NULL, matchNode = NULL; - char *detach_xml = NULL, buf[64]; + char *detach_xml = NULL; + char buf[64]; int diff_mac, ret = -1; size_t i; -- 2.31.1

Use 'ostype' instead of generic 'str', to discourage reuse. Also mark it as autofree. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index a2bf5c05fc..cf0803dcd3 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1288,7 +1288,8 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) bool ret = true; int autostart; unsigned int id; - char *str, uuid[VIR_UUID_STRING_BUFLEN]; + char uuid[VIR_UUID_STRING_BUFLEN]; + g_autofree char *ostype = NULL; int has_managed_save = 0; virshControl *priv = ctl->privData; g_auto(GStrv) messages = NULL; @@ -1306,10 +1307,8 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) if (virDomainGetUUIDString(dom, &uuid[0]) == 0) vshPrint(ctl, "%-15s %s\n", _("UUID:"), uuid); - if ((str = virDomainGetOSType(dom))) { - vshPrint(ctl, "%-15s %s\n", _("OS Type:"), str); - VIR_FREE(str); - } + if ((ostype = virDomainGetOSType(dom))) + vshPrint(ctl, "%-15s %s\n", _("OS Type:"), ostype); if (virDomainGetInfo(dom, &info) == 0) { vshPrint(ctl, "%-15s %s\n", _("State:"), -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-completer-checkpoint.c | 4 +- tools/virsh-completer-domain.c | 15 +- tools/virsh-completer-snapshot.c | 3 +- tools/virsh-domain-monitor.c | 29 +-- tools/virsh-domain.c | 303 ++++++++++------------------- 5 files changed, 116 insertions(+), 238 deletions(-) diff --git a/tools/virsh-completer-checkpoint.c b/tools/virsh-completer-checkpoint.c index 1296741061..b6d6c93e85 100644 --- a/tools/virsh-completer-checkpoint.c +++ b/tools/virsh-completer-checkpoint.c @@ -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; } diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 0df11807e1..d1430c951a 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -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; } diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snapshot.c index e8109ee1e2..535841cf2e 100644 --- a/tools/virsh-completer-snapshot.c +++ b/tools/virsh-completer-snapshot.c @@ -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); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index cf0803dcd3..d79f807d8b 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -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; } @@ -905,7 +904,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; @@ -932,7 +931,6 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) } cleanup: - virshDomainFree(dom); return ret; } @@ -1006,7 +1004,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; @@ -1118,7 +1116,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(params); - virshDomainFree(dom); return ret; } #undef DOMBLKSTAT_LEGACY_PRINT @@ -1150,7 +1147,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; @@ -1193,7 +1190,6 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -1218,7 +1214,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; @@ -1255,7 +1251,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; } @@ -1281,7 +1276,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; @@ -1364,7 +1359,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(); @@ -1379,7 +1373,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 { @@ -1400,7 +1393,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) } } - virshDomainFree(dom); return ret; } @@ -1429,7 +1421,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; @@ -1452,7 +1444,6 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) } cleanup: - virshDomainFree(dom); return ret; } @@ -1493,7 +1484,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"); @@ -1552,7 +1543,6 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -2385,7 +2375,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; @@ -2478,7 +2468,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(ifaces); - virshDomainFree(dom); return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ae979ddd49..b671ae398f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -321,7 +321,7 @@ static const vshCmdOptDef opts_attach_device[] = { static bool cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *from = NULL; char *buffer; int rv; @@ -373,7 +373,6 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -882,7 +881,7 @@ virshParseRateStr(vshControl *ctl, static bool cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *mac = NULL, *target = NULL, *script = NULL, *type = NULL, *source = NULL, *model = NULL, *inboundStr = NULL, *outboundStr = NULL, *alias = NULL; @@ -1074,7 +1073,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - virshDomainFree(dom); return functionReturn; } @@ -1103,7 +1101,7 @@ static const vshCmdOptDef opts_autostart[] = { static bool cmdAutostart(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; int autostart; @@ -1117,7 +1115,6 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Failed to mark domain '%s' as autostarted"), name); else vshError(ctl, _("Failed to unmark domain '%s' as autostarted"), name); - virshDomainFree(dom); return false; } @@ -1126,7 +1123,6 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) else vshPrintExtra(ctl, _("Domain '%s' unmarked as autostarted\n"), name); - virshDomainFree(dom); return true; } @@ -1320,7 +1316,7 @@ static const vshCmdOptDef opts_blkdeviotune[] = { static bool cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *name, *disk; const char *group_name = NULL; unsigned long long value; @@ -1441,7 +1437,6 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -1506,7 +1501,7 @@ static const vshCmdOptDef opts_blkiotune[] = { static bool cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *device_weight = NULL; const char *device_riops = NULL; const char *device_wiops = NULL; @@ -1638,7 +1633,6 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -2019,7 +2013,7 @@ static const vshCmdOptDef opts_blockcommit[] = { static bool cmdBlockcommit(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; bool verbose = vshCommandOptBool(cmd, "verbose"); bool pivot = vshCommandOptBool(cmd, "pivot"); @@ -2156,7 +2150,6 @@ cmdBlockcommit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2262,7 +2255,7 @@ static const vshCmdOptDef opts_blockcopy[] = { static bool cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *dest = NULL; const char *format = NULL; unsigned long bandwidth = 0; @@ -2473,7 +2466,6 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xmlstr); virTypedParamsFree(params, nparams); - virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2683,7 +2675,7 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) bool async = vshCommandOptBool(cmd, "async"); bool info = vshCommandOptBool(cmd, "info"); bool bandwidth = vshCommandOptBool(cmd, "bandwidth"); - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *path; VSH_EXCLUSIVE_OPTIONS("raw", "abort"); @@ -2715,7 +2707,6 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) ret = virshBlockJobInfo(ctl, dom, path, raw, bytes); cleanup: - virshDomainFree(dom); return ret; } @@ -2778,7 +2769,7 @@ static const vshCmdOptDef opts_blockpull[] = { static bool cmdBlockpull(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; bool blocking = vshCommandOptBool(cmd, "wait"); bool verbose = vshCommandOptBool(cmd, "verbose"); @@ -2861,7 +2852,6 @@ cmdBlockpull(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2898,7 +2888,7 @@ static const vshCmdOptDef opts_blockresize[] = { static bool cmdBlockresize(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *path = NULL; unsigned long long size = 0; unsigned int flags = 0; @@ -2926,7 +2916,6 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) ret = true; } - virshDomainFree(dom); return ret; } @@ -3000,7 +2989,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom, static bool cmdConsole(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; bool force = vshCommandOptBool(cmd, "force"); bool safe = vshCommandOptBool(cmd, "safe"); @@ -3021,7 +3010,6 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) ret = cmdRunConsole(ctl, dom, name, flags); cleanup: - virshDomainFree(dom); return ret; } #endif /* WIN32 */ @@ -3064,7 +3052,7 @@ static const vshCmdOptDef opts_domif_setlink[] = { static bool cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *iface; const char *state; char *value; @@ -3194,7 +3182,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(xml_buf); - virshDomainFree(dom); return ret; } @@ -3236,7 +3223,7 @@ static const vshCmdOptDef opts_domiftune[] = { static bool cmdDomIftune(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name = NULL, *device = NULL, *inboundStr = NULL, *outboundStr = NULL; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -3386,7 +3373,6 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -3417,7 +3403,7 @@ static const vshCmdOptDef opts_suspend[] = { static bool cmdSuspend(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; bool ret = true; @@ -3431,7 +3417,6 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -3472,7 +3457,7 @@ static const vshCmdOptDef opts_dom_pm_suspend[] = { static bool cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; bool ret = false; const char *target = NULL; @@ -3505,7 +3490,6 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -3532,7 +3516,7 @@ static const vshCmdOptDef opts_dom_pm_wakeup[] = { static bool cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; bool ret = false; unsigned int flags = 0; @@ -3552,7 +3536,6 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -3625,7 +3608,7 @@ typedef struct { static bool cmdUndefine(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *name = NULL; /* Flags to attempt. */ @@ -3974,7 +3957,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_nodes); xmlFreeDoc(doc); xmlXPathFreeContext(ctxt); - virshDomainFree(dom); return ret; error: @@ -4077,7 +4059,7 @@ cmdStartGetFDs(vshControl *ctl, static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); @@ -4152,7 +4134,6 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); VIR_FREE(fds); return ret; } @@ -4202,7 +4183,7 @@ doSave(void *opaque) virshCtrlData *data = opaque; vshControl *ctl = data->ctl; const vshCmd *cmd = data->cmd; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *name = NULL; const char *to = NULL; unsigned int flags = 0; @@ -4253,7 +4234,6 @@ doSave(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: #endif /* !WIN32 */ - virshDomainFree(dom); VIR_FREE(xml); g_main_loop_quit(data->eventLoop); } @@ -4464,7 +4444,7 @@ virshWatchJob(vshControl *ctl, static bool cmdSave(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; virThread workerThread; bool verbose = false; const char *to = NULL; @@ -4502,7 +4482,6 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain '%s' saved to %s\n"), name, to); cleanup: - virshDomainFree(dom); return !data.ret; } @@ -4735,7 +4714,7 @@ doManagedsave(void *opaque) virshCtrlData *data = opaque; vshControl *ctl = data->ctl; const vshCmd *cmd = data->cmd; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *name; unsigned int flags = 0; #ifndef WIN32 @@ -4768,14 +4747,13 @@ doManagedsave(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: #endif /* !WIN32 */ - virshDomainFree(dom); g_main_loop_quit(data->eventLoop); } static bool cmdManagedSave(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool verbose = false; const char *name = NULL; virThread workerThread; @@ -4809,7 +4787,6 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain '%s' state saved by libvirt\n"), name); cleanup: - virshDomainFree(dom); return !data.ret; } @@ -4834,7 +4811,7 @@ static const vshCmdOptDef opts_managedsaveremove[] = { static bool cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; bool ret = false; int hassave; @@ -4864,7 +4841,6 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -4898,7 +4874,7 @@ static bool cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned int getxml_flags = VIR_DOMAIN_XML_SECURE; unsigned int define_flags = 0; @@ -4930,7 +4906,6 @@ cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -4960,7 +4935,7 @@ static bool cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned int flags = 0; char *xml = NULL; @@ -4977,7 +4952,6 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); VIR_FREE(xml); return ret; } @@ -5017,7 +4991,7 @@ static bool cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *xmlfile = NULL; char *xml = NULL; unsigned int flags = 0; @@ -5049,7 +5023,6 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); VIR_FREE(xml); return ret; } @@ -5186,7 +5159,7 @@ static bool cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) { char *schedulertype; - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; virTypedParameterPtr params = NULL; virTypedParameterPtr updates = NULL; int nparams = 0; @@ -5283,7 +5256,6 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); virTypedParamsFree(updates, nupdates); - virshDomainFree(dom); return ret_val; } @@ -5423,7 +5395,7 @@ doDump(void *opaque) virshCtrlData *data = opaque; vshControl *ctl = data->ctl; const vshCmd *cmd = data->cmd; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *name = NULL; const char *to = NULL; unsigned int flags = 0; @@ -5489,14 +5461,13 @@ doDump(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: #endif /* !WIN32 */ - virshDomainFree(dom); g_main_loop_quit(data->eventLoop); } static bool cmdDump(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool verbose = false; const char *name = NULL; const char *to = NULL; @@ -5534,7 +5505,6 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); cleanup: - virshDomainFree(dom); return !data.ret; } @@ -5595,7 +5565,7 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime) static bool cmdScreenshot(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name = NULL; char *file = NULL; int fd = -1; @@ -5669,7 +5639,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - virshDomainFree(dom); if (st) virStreamFree(st); VIR_FORCE_CLOSE(fd); @@ -5728,7 +5697,7 @@ VIR_ENUM_IMPL(virshDomainLifecycleAction, static bool cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); @@ -5773,7 +5742,6 @@ cmdSetLifecycleAction(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -5812,7 +5780,7 @@ static const vshCmdOptDef opts_set_user_password[] = { static bool cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *name; const char *password = NULL; const char *user = NULL; @@ -5838,7 +5806,6 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } /* @@ -5862,7 +5829,7 @@ static const vshCmdOptDef opts_resume[] = { static bool cmdResume(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; const char *name; @@ -5876,7 +5843,6 @@ cmdResume(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -5906,7 +5872,7 @@ static const vshCmdOptDef opts_shutdown[] = { static bool cmdShutdown(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *name; const char *mode = NULL; @@ -5961,7 +5927,6 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); g_strfreev(modes); return ret; } @@ -5992,7 +5957,7 @@ static const vshCmdOptDef opts_reboot[] = { static bool cmdReboot(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *name; const char *mode = NULL; @@ -6042,7 +6007,6 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); g_strfreev(modes); return ret; } @@ -6068,7 +6032,7 @@ static const vshCmdOptDef opts_reset[] = { static bool cmdReset(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; const char *name; @@ -6082,7 +6046,6 @@ cmdReset(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -6199,7 +6162,7 @@ static bool cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) { virDomainJobInfo info; - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *unit; double val; @@ -6499,7 +6462,6 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); virTypedParamsFree(params, nparams); return ret; @@ -6529,7 +6491,7 @@ static const vshCmdOptDef opts_domjobabort[] = { static bool cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) @@ -6538,7 +6500,6 @@ cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) if (virDomainAbortJob(dom) < 0) ret = false; - virshDomainFree(dom); return ret; } @@ -6662,7 +6623,7 @@ virshCPUCountCollect(vshControl *ctl, static bool cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); bool active = vshCommandOptBool(cmd, "active"); @@ -6735,7 +6696,6 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -7130,7 +7090,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen, static bool cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; unsigned int vcpu = 0; const char *cpulist = NULL; bool ret = false; @@ -7195,7 +7155,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virshDomainFree(dom); return ret; } @@ -7229,7 +7188,7 @@ static const vshCmdOptDef opts_emulatorpin[] = { static bool cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *cpulist = NULL; bool ret = false; unsigned char *cpumap = NULL; @@ -7257,13 +7216,11 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) { - virshDomainFree(dom); return false; } query = !cpulist; if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0) { - virshDomainFree(dom); return false; } @@ -7300,7 +7257,6 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: VIR_FREE(cpumap); - virshDomainFree(dom); return ret; } @@ -7345,7 +7301,7 @@ static const vshCmdOptDef opts_setvcpus[] = { static bool cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; unsigned int count = 0; bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); @@ -7396,7 +7352,6 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -7436,7 +7391,7 @@ static const vshCmdOptDef opts_guestvcpus[] = { static bool cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool enable = vshCommandOptBool(cmd, "enable"); bool disable = vshCommandOptBool(cmd, "disable"); virTypedParameterPtr params = NULL; @@ -7483,7 +7438,6 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; } @@ -7526,7 +7480,7 @@ static const vshCmdOptDef opts_setvcpu[] = { static bool cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool enable = vshCommandOptBool(cmd, "enable"); bool disable = vshCommandOptBool(cmd, "disable"); bool config = vshCommandOptBool(cmd, "config"); @@ -7566,7 +7520,6 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -7606,7 +7559,7 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) { unsigned long long threshold; const char *dev = NULL; - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "dev", &dev)) @@ -7625,7 +7578,6 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -7653,7 +7605,7 @@ static const vshCmdOptDef opts_iothreadinfo[] = { static bool cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -7713,7 +7665,6 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) virDomainIOThreadInfoFree(info[i]); VIR_FREE(info); vshTableFree(table); - virshDomainFree(dom); return ret; } @@ -7753,7 +7704,7 @@ static const vshCmdOptDef opts_iothreadpin[] = { static bool cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *cpulist = NULL; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); @@ -7797,7 +7748,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virshDomainFree(dom); return ret; } @@ -7830,7 +7780,7 @@ static const vshCmdOptDef opts_iothreadadd[] = { static bool cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; bool ret = false; bool config = vshCommandOptBool(cmd, "config"); @@ -7862,7 +7812,6 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -7908,7 +7857,7 @@ static const vshCmdOptDef opts_iothreadset[] = { static bool cmdIOThreadSet(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; int id = 0; bool ret = false; bool live = vshCommandOptBool(cmd, "live"); @@ -7962,7 +7911,6 @@ cmdIOThreadSet(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -8001,7 +7949,7 @@ static const vshCmdOptDef opts_iothreaddel[] = { static bool cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; bool ret = false; bool config = vshCommandOptBool(cmd, "config"); @@ -8033,7 +7981,6 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -8090,7 +8037,7 @@ vshCPUStatsPrintField(vshControl *ctl, static bool cmdCPUStats(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; virTypedParameterPtr params = NULL; int max_id, cpu = 0, show_count = -1, nparams = 0, stats_per_cpu; size_t i, j; @@ -8211,7 +8158,6 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; failed_stats: @@ -8263,7 +8209,7 @@ static const vshCmdOptDef opts_create[] = { static bool cmdCreate(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *from = NULL; bool ret = false; char *buffer; @@ -8307,7 +8253,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (console) cmdRunConsole(ctl, dom, NULL, 0); #endif - virshDomainFree(dom); ret = true; cleanup: @@ -8341,7 +8286,7 @@ static const vshCmdOptDef opts_define[] = { static bool cmdDefine(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *from = NULL; bool ret = true; char *buffer; @@ -8366,7 +8311,6 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (dom != NULL) { vshPrintExtra(ctl, _("Domain '%s' defined from %s\n"), virDomainGetName(dom), from); - virshDomainFree(dom); } else { vshError(ctl, _("Failed to define domain from %s"), from); ret = false; @@ -8399,7 +8343,7 @@ static const vshCmdOptDef opts_destroy[] = { static bool cmdDestroy(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; const char *name; unsigned int flags = 0; @@ -8423,7 +8367,6 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -8464,7 +8407,7 @@ static const vshCmdOptDef opts_desc[] = { static bool cmdDesc(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8583,7 +8526,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) unlink(tmp); VIR_FREE(tmp); } - virshDomainFree(dom); return ret; } @@ -8650,7 +8592,7 @@ virshDomainGetEditMetadata(vshControl *ctl G_GNUC_UNUSED, static bool cmdMetadata(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8726,7 +8668,6 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -8811,7 +8752,7 @@ virshKeyCodeGetInt(const char *key_name) static bool cmdSendKey(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const char *codeset_option; int codeset; @@ -8862,7 +8803,6 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -8993,7 +8933,7 @@ static const vshCmdOptDef opts_setmem[] = { static bool cmdSetmem(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; @@ -9034,7 +8974,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -9071,7 +9010,7 @@ static const vshCmdOptDef opts_setmaxmem[] = { static bool cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; @@ -9109,7 +9048,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -9197,7 +9135,7 @@ virshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd, static bool cmdMemtune(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; long long tmpVal; int nparams = 0; int maxparams = 0; @@ -9280,7 +9218,6 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -9366,7 +9303,7 @@ virshPrintPerfStatus(vshControl *ctl, virTypedParameterPtr params, int nparams) static bool cmdPerf(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; int nparams = 0; int maxparams = 0; virTypedParameterPtr params = NULL; @@ -9418,7 +9355,6 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; } @@ -9459,7 +9395,7 @@ static const vshCmdOptDef opts_numatune[] = { static bool cmdNumatune(vshControl * ctl, const vshCmd * cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; int nparams = 0; int maxparams = 0; size_t i; @@ -9551,7 +9487,6 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; save_error: @@ -9761,7 +9696,7 @@ static const vshCmdOptDef opts_qemu_monitor_event[] = { static bool cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; unsigned int flags = 0; int eventId = -1; @@ -9819,7 +9754,6 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >= 0 && virConnectDomainQemuMonitorEventDeregister(priv->conn, eventId) < 0) ret = false; - virshDomainFree(dom); return ret; } @@ -9849,7 +9783,7 @@ static const vshCmdOptDef opts_qemu_attach[] = { static bool cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned int flags = 0; unsigned int pid_value; /* API uses unsigned int, not pid_t */ virshControl *priv = ctl->privData; @@ -9864,7 +9798,6 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%s' attached to pid %u\n"), virDomainGetName(dom), pid_value); - virshDomainFree(dom); return true; } @@ -9911,7 +9844,7 @@ static const vshCmdOptDef opts_qemu_agent_command[] = { static bool cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; char *guest_agent_cmd = NULL; char *result = NULL; @@ -9979,7 +9912,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(result); VIR_FREE(guest_agent_cmd); - virshDomainFree(dom); return ret; } @@ -10014,7 +9946,7 @@ static const vshCmdOptDef opts_lxc_enter_namespace[] = { static bool cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; const vshCmdOpt *opt = NULL; char **cmdargv = NULL; @@ -10109,7 +10041,6 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(seclabel); VIR_FREE(secmodel); - virshDomainFree(dom); VIR_FREE(cmdargv); return ret; } @@ -10151,7 +10082,7 @@ static const vshCmdOptDef opts_dumpxml[] = { static bool cmdDumpXML(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = true; char *dump; unsigned int flags = 0; @@ -10180,7 +10111,6 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) ret = false; } - virshDomainFree(dom); return ret; } @@ -10278,7 +10208,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) char *xmlData = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 || vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0) @@ -10313,7 +10243,6 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) } cleanup: - virshDomainFree(dom); VIR_FREE(xmlData); VIR_FREE(configData); return ret; @@ -10345,14 +10274,13 @@ static const vshCmdOptDef opts_domname[] = { static bool cmdDomname(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, VIRSH_BYID|VIRSH_BYUUID))) return false; vshPrint(ctl, "%s\n", virDomainGetName(dom)); - virshDomainFree(dom); return true; } @@ -10383,7 +10311,7 @@ static const vshCmdOptDef opts_domrename[] = { static bool cmdDomrename(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *new_name = NULL; bool ret = false; @@ -10400,7 +10328,6 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -10426,7 +10353,7 @@ static const vshCmdOptDef opts_domid[] = { static bool cmdDomid(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; unsigned int id; if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, @@ -10438,7 +10365,6 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", "-"); else vshPrint(ctl, "%d\n", id); - virshDomainFree(dom); return true; } @@ -10463,7 +10389,7 @@ static const vshCmdOptDef opts_domuuid[] = { static bool cmdDomuuid(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; char uuid[VIR_UUID_STRING_BUFLEN]; if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, @@ -10475,7 +10401,6 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, "%s", _("failed to get domain UUID")); - virshDomainFree(dom); return true; } @@ -10684,7 +10609,7 @@ static const vshCmdOptDef opts_migrate[] = { static void doMigrate(void *opaque) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *desturi = NULL; const char *opt = NULL; unsigned int flags = 0; @@ -10972,10 +10897,9 @@ doMigrate(void *opaque) data->ret = 0; } else { /* For traditional live migration, connect to the destination host directly. */ - virDomainPtr ddom = NULL; + g_autoptr(virshDomain) ddom = NULL; if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) { - virshDomainFree(ddom); data->ret = 0; } } @@ -10986,7 +10910,6 @@ doMigrate(void *opaque) out_sig: #endif /* !WIN32 */ virTypedParamsFree(params, nparams); - virshDomainFree(dom); g_main_loop_quit(data->eventLoop); return; @@ -11046,7 +10969,7 @@ virshMigrateIteration(virConnectPtr conn G_GNUC_UNUSED, static bool cmdMigrate(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; virThread workerThread; bool verbose = false; unsigned int timeout = 0; @@ -11144,7 +11067,6 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) virConnectClose(data.dconn); if (iterEvent != -1) virConnectDomainEventDeregisterAny(priv->conn, iterEvent); - virshDomainFree(dom); return !data.ret; } @@ -11174,7 +11096,7 @@ static const vshCmdOptDef opts_migrate_setmaxdowntime[] = { static bool cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned long long downtime = 0; bool ret = false; @@ -11194,7 +11116,6 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virshDomainFree(dom); return ret; } @@ -11220,7 +11141,7 @@ static const vshCmdOptDef opts_migrate_getmaxdowntime[] = { static bool cmdMigrateGetMaxDowntime(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned long long downtime; bool ret = false; @@ -11234,7 +11155,6 @@ cmdMigrateGetMaxDowntime(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virshDomainFree(dom); return ret; } @@ -11266,7 +11186,7 @@ static const vshCmdOptDef opts_migrate_compcache[] = { static bool cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned long long size = 0; bool ret = false; const char *unit; @@ -11292,7 +11212,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -11327,7 +11246,7 @@ static const vshCmdOptDef opts_migrate_setspeed[] = { static bool cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth = 0; unsigned int flags = 0; bool ret = false; @@ -11347,7 +11266,6 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virshDomainFree(dom); return ret; } @@ -11376,7 +11294,7 @@ static const vshCmdOptDef opts_migrate_getspeed[] = { static bool cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth; unsigned int flags = 0; bool ret = false; @@ -11395,7 +11313,6 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virshDomainFree(dom); return ret; } @@ -11421,7 +11338,7 @@ static const vshCmdOptDef opts_migrate_postcopy[] = { static bool cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) @@ -11433,7 +11350,6 @@ cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -11474,7 +11390,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml = NULL; xmlXPathContextPtr ctxt = NULL; - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; bool ret = false; char *xpath = NULL; @@ -11704,7 +11620,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(output); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); return ret; } @@ -11731,7 +11646,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml = NULL; xmlXPathContextPtr ctxt = NULL; - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; int port = 0; char *listen_addr = NULL; @@ -11780,7 +11695,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virshDomainFree(dom); return ret; } @@ -12004,7 +11918,7 @@ static const vshCmdOptDef opts_detach_device_alias[] = { static bool cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *alias = NULL; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -12035,7 +11949,6 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -12070,7 +11983,7 @@ static const vshCmdOptDef opts_update_device[] = { static bool cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; const char *from = NULL; char *buffer = NULL; bool ret = false; @@ -12118,7 +12031,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - virshDomainFree(dom); return ret; } @@ -12249,7 +12161,7 @@ virshDomainDetachInterface(char *doc, static bool cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; char *doc_live = NULL, *doc_config = NULL; const char *mac = NULL, *type = NULL; int flags = 0; @@ -12307,7 +12219,6 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(doc_live); VIR_FREE(doc_config); - virshDomainFree(dom); return ret; } @@ -12612,7 +12523,7 @@ static bool cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) { char *disk_xml = NULL; - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *target = NULL; char *doc = NULL; int ret; @@ -12683,7 +12594,6 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) xmlFreeNode(disk_node); VIR_FREE(disk_xml); VIR_FREE(doc); - virshDomainFree(dom); return functionReturn; } @@ -12713,8 +12623,8 @@ static bool cmdEdit(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - virDomainPtr dom = NULL; - virDomainPtr dom_edited = NULL; + g_autoptr(virshDomain) dom = NULL; + g_autoptr(virshDomain) dom_edited = NULL; unsigned int query_flags = VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE; unsigned int define_flags = VIR_DOMAIN_DEFINE_VALIDATE; virshControl *priv = ctl->privData; @@ -12750,8 +12660,6 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); - virshDomainFree(dom_edited); return ret; } @@ -13569,7 +13477,7 @@ static const vshCmdOptDef opts_event[] = { static bool cmdEvent(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; int timeout = 0; virshDomEventData *data = NULL; @@ -13679,7 +13587,6 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(data); } - virshDomainFree(dom); return ret; } @@ -13745,7 +13652,7 @@ static const vshCmdOptDef opts_change_media[] = { static bool cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *source = NULL; const char *path = NULL; char *doc = NULL; @@ -13845,7 +13752,6 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) VIR_FREE(doc); xmlFreeNode(disk_node); VIR_FREE(disk_xml); - virshDomainFree(dom); return ret; } @@ -13876,7 +13782,7 @@ static const vshCmdOptDef opts_domfstrim[] = { static bool cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; bool ret = false; unsigned long long minimum = 0; const char *mountPoint = NULL; @@ -13899,7 +13805,6 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -13925,7 +13830,7 @@ static const vshCmdOptDef opts_domfsfreeze[] = { static bool cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; int ret = -1; const vshCmdOpt *opt = NULL; const char **mountpoints = NULL; @@ -13949,7 +13854,6 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virshDomainFree(dom); return ret >= 0; } @@ -13975,7 +13879,7 @@ static const vshCmdOptDef opts_domfsthaw[] = { static bool cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; int ret = -1; const vshCmdOpt *opt = NULL; const char **mountpoints = NULL; @@ -13999,7 +13903,6 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virshDomainFree(dom); return ret >= 0; } @@ -14021,7 +13924,7 @@ static const vshCmdOptDef opts_domfsinfo[] = { static bool cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; int rc = -1; size_t i, j; virDomainFSInfoPtr *info = NULL; @@ -14081,7 +13984,6 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(info); } vshTableFree(table); - virshDomainFree(dom); return ret; } @@ -14111,7 +14013,7 @@ static const vshCmdOptDef opts_guest_agent_timeout[] = { static bool cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; int timeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; const unsigned int flags = 0; bool ret = false; @@ -14127,7 +14029,6 @@ cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -14177,7 +14078,7 @@ static const vshCmdOptDef opts_guestinfo[] = { static bool cmdGuestInfo(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom; + g_autoptr(virshDomain) dom = NULL; bool ret = false; virTypedParameterPtr params = NULL; int nparams = 0; @@ -14213,7 +14114,6 @@ cmdGuestInfo(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virshDomainFree(dom); return ret; } @@ -14244,7 +14144,7 @@ static const vshCmdOptDef opts_get_user_sshkeys[] = { static bool cmdGetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *user; g_auto(GStrv) keys = NULL; int nkeys = 0; @@ -14268,7 +14168,6 @@ cmdGetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -14312,7 +14211,7 @@ static const vshCmdOptDef opts_set_user_sshkeys[] = { static bool cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; const char *user; const char *from; g_autofree char *buffer = NULL; @@ -14369,7 +14268,6 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } @@ -14403,7 +14301,7 @@ static const vshCmdOptDef opts_domdirtyrate_calc[] = { static bool cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) { - virDomainPtr dom = NULL; + g_autoptr(virshDomain) dom = NULL; int seconds = 1; /* the default value is 1 */ bool ret = false; @@ -14421,7 +14319,6 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virshDomainFree(dom); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-completer-domain.c | 6 ++---- tools/virsh-domain-monitor.c | 12 ++++-------- tools/virsh-domain.c | 27 +++++++++------------------ tools/virsh-host.c | 15 +++++---------- tools/virsh-interface.c | 6 ++---- tools/virsh-volume.c | 3 +-- 6 files changed, 23 insertions(+), 46 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index d1430c951a..4cdc533a07 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -479,7 +479,7 @@ virshDomainVcpuCompleter(vshControl *ctl, { g_autoptr(virshDomain) dom = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; char **ret = NULL; @@ -506,7 +506,6 @@ virshDomainVcpuCompleter(vshControl *ctl, ret = g_steal_pointer(&tmp); cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } @@ -519,7 +518,7 @@ virshDomainVcpulistCompleter(vshControl *ctl, { g_autoptr(virshDomain) dom = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; g_auto(GStrv) vcpulist = NULL; @@ -550,7 +549,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist); cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index d79f807d8b..cabf968393 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -56,7 +56,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, { char *desc = NULL; xmlDocPtr doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int type; if (title) @@ -92,7 +92,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, desc = g_strdup(""); cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); return desc; @@ -595,7 +594,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) bool ret = false; unsigned int flags = 0; xmlDocPtr xmldoc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int ndisks; xmlNodePtr *disks = NULL; size_t i; @@ -694,7 +693,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) VIR_FREE(device); VIR_FREE(type); VIR_FREE(disks); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); return ret; } @@ -723,7 +721,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) bool ret = false; unsigned int flags = 0; xmlDocPtr xmldoc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int ninterfaces; xmlNodePtr *interfaces = NULL; size_t i; @@ -782,7 +780,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) vshTableFree(table); VIR_FREE(interfaces); xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); return ret; } @@ -824,7 +821,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] = ""; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *interfaces = NULL; int ninterfaces; unsigned int flags = 0; @@ -877,7 +874,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) VIR_FREE(state); VIR_FREE(interfaces); VIR_FREE(xpath); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b671ae398f..398190bb5b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3065,7 +3065,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) unsigned int xmlflags = 0; size_t i; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlXPathObjectPtr obj = NULL; xmlNodePtr cur = NULL; char *xml_buf = NULL; @@ -3179,7 +3179,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) cleanup: xmlXPathFreeObject(obj); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(xml_buf); @@ -3639,7 +3638,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) virshUndefineVolume *vols = NULL; /* info about the volumes to delete */ size_t nvols = 0; xmlDocPtr doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */ int nvol_nodes; char *source = NULL; @@ -3956,7 +3955,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_nodes); xmlFreeDoc(doc); - xmlXPathFreeContext(ctxt); return ret; error: @@ -6555,7 +6553,7 @@ virshCPUCountCollect(vshControl *ctl, virDomainInfo info; int count; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; if (checkState && ((flags & VIR_DOMAIN_AFFECT_LIVE && virDomainIsActive(dom) < 1) || @@ -6614,7 +6612,6 @@ virshCPUCountCollect(vshControl *ctl, ret = count; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; @@ -6759,7 +6756,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, unsigned int flags = 0; virBitmap *ret = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; int nnodes; size_t i; @@ -6816,7 +6813,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, cleanup: VIR_FREE(online); VIR_FREE(nodes); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } @@ -11389,7 +11385,7 @@ static bool cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; bool ret = false; @@ -11618,7 +11614,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(passwd); VIR_FREE(listen_addr); VIR_FREE(output); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } @@ -11645,7 +11640,7 @@ static bool cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; bool ret = false; int port = 0; @@ -11693,7 +11688,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(listen_addr); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } @@ -11720,7 +11714,7 @@ static bool cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; bool ret = false; char *tty = NULL; @@ -11734,7 +11728,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(tty); return ret; @@ -12078,7 +12071,7 @@ virshDomainDetachInterface(char *doc, { xmlDocPtr xml = NULL; xmlXPathObjectPtr obj = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL, matchNode = NULL; char *detach_xml = NULL; char buf[64]; @@ -12153,7 +12146,6 @@ virshDomainDetachInterface(char *doc, VIR_FREE(detach_xml); xmlFreeDoc(xml); xmlXPathFreeObject(obj); - xmlXPathFreeContext(ctxt); return ret == 0; } @@ -12259,7 +12251,7 @@ virshFindDisk(const char *doc, { xmlDocPtr xml = NULL; xmlXPathObjectPtr obj = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL; xmlNodePtr ret = NULL; size_t i; @@ -12334,7 +12326,6 @@ virshFindDisk(const char *doc, cleanup: xmlXPathFreeObject(obj); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 7b47b7583d..b2d3a9c85f 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -168,7 +168,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) size_t i; char *cap_xml = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); @@ -243,7 +243,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(nodes_free); @@ -308,7 +307,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) int nodes_cnt; char *cap_xml = NULL; xmlDocPtr doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; bool all = vshCommandOptBool(cmd, "all"); bool cellno = vshCommandOptBool(cmd, "cellno"); bool pagesz = vshCommandOptBool(cmd, "pagesize"); @@ -443,7 +442,6 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); VIR_FREE(cap_xml); VIR_FREE(nodes); @@ -507,7 +505,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; char *cap_xml = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; virshControl *priv = ctl->privData; @@ -571,7 +569,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(cap_xml); @@ -607,7 +604,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) int vcpus = -1; char *caps = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; bool ret = false; @@ -631,7 +628,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(caps); return ret; @@ -1125,7 +1121,7 @@ vshExtractCPUDefXMLs(vshControl *ctl, char *buffer = NULL; char *xmlStr = NULL; xmlDocPtr xml = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; char *doc; size_t i; @@ -1188,7 +1184,6 @@ vshExtractCPUDefXMLs(vshControl *ctl, VIR_FREE(buffer); VIR_FREE(xmlStr); xmlFreeDoc(xml); - xmlXPathFreeContext(ctxt); VIR_FREE(nodes); return cpus; diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 41acae5dcb..1a94eba1c3 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -822,7 +822,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) xmlChar *br_xml = NULL; int br_xml_size; xmlDocPtr xml_doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr top_node, br_node, if_node, cur; virshControl *priv = ctl->privData; @@ -1001,7 +1001,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(if_type); VIR_FREE(if2_name); VIR_FREE(delay_str); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml_doc); return ret; } @@ -1044,7 +1043,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) xmlChar *if_xml = NULL; int if_xml_size; xmlDocPtr xml_doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr top_node, if_node, cur; virshControl *priv = ctl->privData; @@ -1201,7 +1200,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(br_xml); VIR_FREE(if_type); VIR_FREE(if_name); - xmlXPathFreeContext(ctxt); xmlFreeDoc(xml_doc); return ret; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index fe632b1b19..c9c4310cbd 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -526,7 +526,7 @@ static xmlChar * virshMakeCloneXML(const char *origxml, const char *newname) { xmlDocPtr doc = NULL; - xmlXPathContextPtr ctxt = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; xmlXPathObjectPtr obj = NULL; xmlChar *newxml = NULL; int size; @@ -545,7 +545,6 @@ virshMakeCloneXML(const char *origxml, const char *newname) cleanup: xmlXPathFreeObject(obj); - xmlXPathFreeContext(ctxt); xmlFreeDoc(doc); return newxml; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 9 +++------ tools/virsh-volume.c | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 398190bb5b..0c60a4de99 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3066,7 +3066,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) size_t i; xmlDocPtr xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlXPathObjectPtr obj = NULL; + g_autoptr(xmlXPathObject) obj = NULL; xmlNodePtr cur = NULL; char *xml_buf = NULL; @@ -3178,7 +3178,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } cleanup: - xmlXPathFreeObject(obj); xmlFreeDoc(xml); VIR_FREE(xml_buf); @@ -12070,7 +12069,7 @@ virshDomainDetachInterface(char *doc, const char *mac) { xmlDocPtr xml = NULL; - xmlXPathObjectPtr obj = NULL; + g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL, matchNode = NULL; char *detach_xml = NULL; @@ -12145,7 +12144,6 @@ virshDomainDetachInterface(char *doc, cleanup: VIR_FREE(detach_xml); xmlFreeDoc(xml); - xmlXPathFreeObject(obj); return ret == 0; } @@ -12250,7 +12248,7 @@ virshFindDisk(const char *doc, int type) { xmlDocPtr xml = NULL; - xmlXPathObjectPtr obj = NULL; + g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL; xmlNodePtr ret = NULL; @@ -12325,7 +12323,6 @@ virshFindDisk(const char *doc, vshError(NULL, _("No disk found whose source path or target is %s"), path); cleanup: - xmlXPathFreeObject(obj); xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index c9c4310cbd..4b179d7d87 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -527,7 +527,7 @@ virshMakeCloneXML(const char *origxml, const char *newname) { xmlDocPtr doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlXPathObjectPtr obj = NULL; + g_autoptr(xmlXPathObject) obj = NULL; xmlChar *newxml = NULL; int size; @@ -544,7 +544,6 @@ virshMakeCloneXML(const char *origxml, const char *newname) xmlDocDumpMemory(doc, &newxml, &size); cleanup: - xmlXPathFreeObject(obj); xmlFreeDoc(doc); return newxml; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-completer-domain.c | 6 ++---- tools/virsh-domain-monitor.c | 12 ++++-------- tools/virsh-domain.c | 27 +++++++++------------------ tools/virsh-host.c | 15 +++++---------- tools/virsh-interface.c | 6 ++---- tools/virsh-volume.c | 3 +-- 6 files changed, 23 insertions(+), 46 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 4cdc533a07..471f9974a1 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -478,7 +478,7 @@ virshDomainVcpuCompleter(vshControl *ctl, unsigned int flags) { g_autoptr(virshDomain) dom = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; @@ -506,7 +506,6 @@ virshDomainVcpuCompleter(vshControl *ctl, ret = g_steal_pointer(&tmp); cleanup: - xmlFreeDoc(xml); return ret; } @@ -517,7 +516,7 @@ virshDomainVcpulistCompleter(vshControl *ctl, unsigned int flags) { g_autoptr(virshDomain) dom = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; @@ -549,7 +548,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist); cleanup: - xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index cabf968393..fb52915cab 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -55,7 +55,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, unsigned int flags) { char *desc = NULL; - xmlDocPtr doc = NULL; + g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int type; @@ -92,7 +92,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, desc = g_strdup(""); cleanup: - xmlFreeDoc(doc); return desc; } @@ -593,7 +592,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { bool ret = false; unsigned int flags = 0; - xmlDocPtr xmldoc = NULL; + g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int ndisks; xmlNodePtr *disks = NULL; @@ -693,7 +692,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) VIR_FREE(device); VIR_FREE(type); VIR_FREE(disks); - xmlFreeDoc(xmldoc); return ret; } @@ -720,7 +718,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { bool ret = false; unsigned int flags = 0; - xmlDocPtr xmldoc = NULL; + g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int ninterfaces; xmlNodePtr *interfaces = NULL; @@ -779,7 +777,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) cleanup: vshTableFree(table); VIR_FREE(interfaces); - xmlFreeDoc(xmldoc); return ret; } @@ -820,7 +817,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) char *xpath = NULL; virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] = ""; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *interfaces = NULL; int ninterfaces; @@ -874,7 +871,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) VIR_FREE(state); VIR_FREE(interfaces); VIR_FREE(xpath); - xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0c60a4de99..fe2bfdaed0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3064,7 +3064,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) unsigned int flags = 0; unsigned int xmlflags = 0; size_t i; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathObject) obj = NULL; xmlNodePtr cur = NULL; @@ -3178,7 +3178,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } cleanup: - xmlFreeDoc(xml); VIR_FREE(xml_buf); return ret; @@ -3636,7 +3635,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) int nvol_list = 0; virshUndefineVolume *vols = NULL; /* info about the volumes to delete */ size_t nvols = 0; - xmlDocPtr doc = NULL; + g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */ int nvol_nodes; @@ -3953,7 +3952,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_list); VIR_FREE(vol_nodes); - xmlFreeDoc(doc); return ret; error: @@ -6551,7 +6549,7 @@ virshCPUCountCollect(vshControl *ctl, int ret = -2; virDomainInfo info; int count; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; if (checkState && @@ -6611,7 +6609,6 @@ virshCPUCountCollect(vshControl *ctl, ret = count; cleanup: - xmlFreeDoc(xml); return ret; } @@ -6754,7 +6751,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, { unsigned int flags = 0; virBitmap *ret = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; int nnodes; @@ -6812,7 +6809,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, cleanup: VIR_FREE(online); VIR_FREE(nodes); - xmlFreeDoc(xml); return ret; } @@ -11383,7 +11379,7 @@ static const vshCmdOptDef opts_domdisplay[] = { static bool cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; @@ -11613,7 +11609,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(passwd); VIR_FREE(listen_addr); VIR_FREE(output); - xmlFreeDoc(xml); return ret; } @@ -11638,7 +11633,7 @@ static const vshCmdOptDef opts_vncdisplay[] = { static bool cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; bool ret = false; @@ -11687,7 +11682,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(listen_addr); - xmlFreeDoc(xml); return ret; } @@ -11712,7 +11706,7 @@ static const vshCmdOptDef opts_ttyconsole[] = { static bool cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; bool ret = false; char *tty = NULL; @@ -11727,7 +11721,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlFreeDoc(xml); VIR_FREE(tty); return ret; } @@ -12068,7 +12061,7 @@ virshDomainDetachInterface(char *doc, const char *type, const char *mac) { - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL, matchNode = NULL; @@ -12143,7 +12136,6 @@ virshDomainDetachInterface(char *doc, cleanup: VIR_FREE(detach_xml); - xmlFreeDoc(xml); return ret == 0; } @@ -12247,7 +12239,7 @@ virshFindDisk(const char *doc, const char *path, int type) { - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL; @@ -12323,7 +12315,6 @@ virshFindDisk(const char *doc, vshError(NULL, _("No disk found whose source path or target is %s"), path); cleanup: - xmlFreeDoc(xml); return ret; } diff --git a/tools/virsh-host.c b/tools/virsh-host.c index b2d3a9c85f..a07f5adbfa 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -167,7 +167,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) bool cellno = vshCommandOptBool(cmd, "cellno"); size_t i; char *cap_xml = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; @@ -243,7 +243,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(nodes_free); VIR_FREE(nodes_id); @@ -306,7 +305,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *nodes = NULL; int nodes_cnt; char *cap_xml = NULL; - xmlDocPtr doc = NULL; + g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; bool all = vshCommandOptBool(cmd, "all"); bool cellno = vshCommandOptBool(cmd, "cellno"); @@ -442,7 +441,6 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlFreeDoc(doc); VIR_FREE(cap_xml); VIR_FREE(nodes); VIR_FREE(counts); @@ -504,7 +502,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) unsigned long long pageCounts[1], tmp; unsigned int flags = 0; char *cap_xml = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; virshControl *priv = ctl->privData; @@ -569,7 +567,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(cap_xml); return ret; @@ -603,7 +600,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) const char *type = NULL; int vcpus = -1; char *caps = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; bool ret = false; @@ -628,7 +625,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - xmlFreeDoc(xml); VIR_FREE(caps); return ret; } @@ -1120,7 +1116,7 @@ vshExtractCPUDefXMLs(vshControl *ctl, char **cpus = NULL; char *buffer = NULL; char *xmlStr = NULL; - xmlDocPtr xml = NULL; + g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *nodes = NULL; char *doc; @@ -1183,7 +1179,6 @@ vshExtractCPUDefXMLs(vshControl *ctl, cleanup: VIR_FREE(buffer); VIR_FREE(xmlStr); - xmlFreeDoc(xml); VIR_FREE(nodes); return cpus; diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 1a94eba1c3..71cc265efc 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -821,7 +821,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) char *if_xml = NULL; xmlChar *br_xml = NULL; int br_xml_size; - xmlDocPtr xml_doc = NULL; + g_autoptr(xmlDoc) xml_doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr top_node, br_node, if_node, cur; virshControl *priv = ctl->privData; @@ -1001,7 +1001,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(if_type); VIR_FREE(if2_name); VIR_FREE(delay_str); - xmlFreeDoc(xml_doc); return ret; } @@ -1042,7 +1041,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) char *br_xml = NULL; xmlChar *if_xml = NULL; int if_xml_size; - xmlDocPtr xml_doc = NULL; + g_autoptr(xmlDoc) xml_doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr top_node, if_node, cur; virshControl *priv = ctl->privData; @@ -1200,7 +1199,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(br_xml); VIR_FREE(if_type); VIR_FREE(if_name); - xmlFreeDoc(xml_doc); return ret; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4b179d7d87..6a1fe6785b 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -525,7 +525,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) static xmlChar * virshMakeCloneXML(const char *origxml, const char *newname) { - xmlDocPtr doc = NULL; + g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathObject) obj = NULL; xmlChar *newxml = NULL; @@ -544,7 +544,6 @@ virshMakeCloneXML(const char *origxml, const char *newname) xmlDocDumpMemory(doc, &newxml, &size); cleanup: - xmlFreeDoc(doc); return newxml; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 9 +++------ tools/virsh-domain.c | 9 +++------ tools/virsh-interface.c | 3 +-- tools/virsh-network.c | 9 +++------ tools/virsh-nwfilter.c | 6 ++---- tools/virsh-pool.c | 3 +-- tools/virsh-secret.c | 3 +-- tools/virsh-volume.c | 3 +-- tools/virt-admin.c | 6 ++---- 9 files changed, 17 insertions(+), 34 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index fb52915cab..4059acc7d6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -602,7 +602,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) char *device = NULL; char *target = NULL; char *source = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptBool(cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; @@ -686,7 +686,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); VIR_FREE(source); VIR_FREE(target); VIR_FREE(device); @@ -723,7 +722,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) int ninterfaces; xmlNodePtr *interfaces = NULL; size_t i; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptBool(cmd, "inactive")) flags |= VIR_DOMAIN_XML_INACTIVE; @@ -775,7 +774,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); VIR_FREE(interfaces); return ret; } @@ -1950,7 +1948,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) char id_buf[VIR_INT64_STR_BUFLEN]; unsigned int id; unsigned int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; /* construct filter flags */ if (vshCommandOptBool(cmd, "inactive") || @@ -2072,7 +2070,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); virshDomainListFree(list); return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fe2bfdaed0..f72ec36f6f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6983,7 +6983,7 @@ virshVcpuPinQuery(vshControl *ctl, size_t i; int ncpus; bool ret = false; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) { if (ncpus == -1) { @@ -7038,7 +7038,6 @@ virshVcpuPinQuery(vshControl *ctl, ret = true; cleanup: - vshTableFree(table); VIR_FREE(cpumap); return ret; } @@ -7604,7 +7603,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) virDomainIOThreadInfoPtr *info = NULL; size_t i; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; bool ret = false; int rc; @@ -7655,7 +7654,6 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < niothreads; i++) virDomainIOThreadInfoFree(info[i]); VIR_FREE(info); - vshTableFree(table); return ret; } @@ -13907,7 +13905,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) int rc = -1; size_t i, j; virDomainFSInfoPtr *info = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; size_t ninfos = 0; bool ret = false; @@ -13962,7 +13960,6 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) virDomainFSInfoFree(info[i]); VIR_FREE(info); } - vshTableFree(table); return ret; } diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 71cc265efc..f88ec188f1 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -348,7 +348,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) struct virshInterfaceList *list = NULL; size_t i; bool ret = false; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; VSH_EXCLUSIVE_OPTIONS_VAR(all, inactive); @@ -381,7 +381,6 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); virshInterfaceListFree(list); return ret; } diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 152df1086b..d641606dde 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -711,7 +711,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) bool optUUID = vshCommandOptBool(cmd, "uuid"); char uuid[VIR_UUID_STRING_BUFLEN]; unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptBool(cmd, "inactive")) flags = VIR_CONNECT_LIST_NETWORKS_INACTIVE; @@ -782,7 +782,6 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); virshNetworkListFree(list); return ret; } @@ -1407,7 +1406,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) size_t i; unsigned int flags = 0; virNetworkPtr network = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0) return false; @@ -1461,7 +1460,6 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); if (leases) { for (i = 0; i < nleases; i++) virNetworkDHCPLeaseFree(leases[i]); @@ -1754,7 +1752,7 @@ cmdNetworkPortList(vshControl *ctl, const vshCmd *cmd) bool optUUID = vshCommandOptBool(cmd, "uuid"); char uuid[VIR_UUID_STRING_BUFLEN]; unsigned int flags = 0; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (optTable + optUUID > 1) { vshError(ctl, "%s", @@ -1795,7 +1793,6 @@ cmdNetworkPortList(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); virshNetworkPortListFree(list); return ret; } diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 640e54446e..acb35e8aa1 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -354,7 +354,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) char uuid[VIR_UUID_STRING_BUFLEN]; bool ret = false; struct virshNWFilterList *list = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (!(list = virshNWFilterListCollect(ctl, 0))) return false; @@ -378,7 +378,6 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); virshNWFilterListFree(list); return ret; } @@ -717,7 +716,7 @@ cmdNWFilterBindingList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) size_t i; bool ret = false; struct virshNWFilterBindingList *list = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (!(list = virshNWFilterBindingListCollect(ctl, 0))) return false; @@ -740,7 +739,6 @@ cmdNWFilterBindingList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); virshNWFilterBindingListFree(list); return ret; } diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 18f3839a4c..5bce5cf06c 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1135,7 +1135,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) bool inactive, all; bool uuid = false; bool name = false; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; inactive = vshCommandOptBool(cmd, "inactive"); all = vshCommandOptBool(cmd, "all"); @@ -1390,7 +1390,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); if (list && list->npools) { for (i = 0; i < list->npools; i++) { VIR_FREE(poolInfoTexts[i].state); diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index cfecbb9b95..4f433fae9c 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -551,7 +551,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) struct virshSecretList *list = NULL; bool ret = false; unsigned int flags = 0; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptBool(cmd, "ephemeral")) flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL; @@ -605,7 +605,6 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); virshSecretListFree(list); return ret; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 6a1fe6785b..af93998d57 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -1415,7 +1415,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) }; struct volInfoText *volInfoTexts = NULL; struct virshStorageVolList *list = NULL; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; /* Look up the pool information given to us by the user */ if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -1513,7 +1513,6 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); /* Safely free the memory allocated in this function */ if (list && list->nvols) { diff --git a/tools/virt-admin.c b/tools/virt-admin.c index dd17743b9d..c8e7ee794a 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -332,7 +332,7 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) char *uri = NULL; virAdmServerPtr *srvs = NULL; vshAdmControl *priv = ctl->privData; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; /* Obtain a list of available servers on the daemon */ if ((nsrvs = virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) { @@ -361,7 +361,6 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - vshTableFree(table); if (srvs) { for (i = 0; i < nsrvs; i++) virAdmServerFree(srvs[i]); @@ -580,7 +579,7 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) virAdmServerPtr srv = NULL; virAdmClientPtr *clts = NULL; vshAdmControl *priv = ctl->privData; - vshTable *table = NULL; + g_autoptr(vshTable) table = NULL; if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0) return false; @@ -621,7 +620,6 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - vshTableFree(table); if (clts) { for (i = 0; i < nclts; i++) virAdmClientFree(clts[i]); -- 2.31.1

Some variables are used in a loop and only freed in the cleanup section because we need to be able to jump out of the loop. Reduce their scope and free them automatically. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 39 +++++++++++++----------------------- tools/virsh-domain.c | 34 +++++++++---------------------- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 4059acc7d6..b07959b1ee 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -598,10 +598,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *disks = NULL; size_t i; bool details = false; - char *type = NULL; - char *device = NULL; - char *target = NULL; - char *source = NULL; g_autoptr(vshTable) table = NULL; if (vshCommandOptBool(cmd, "inactive")) @@ -625,6 +621,11 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) goto cleanup; for (i = 0; i < ndisks; i++) { + g_autofree char *type = NULL; + g_autofree char *device = NULL; + g_autofree char *target = NULL; + g_autofree char *source = NULL; + ctxt->node = disks[i]; type = virXPathString("string(./@type)", ctxt); @@ -674,11 +675,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) NULLSTR_MINUS(source), NULL) < 0) goto cleanup; } - - VIR_FREE(source); - VIR_FREE(target); - VIR_FREE(device); - VIR_FREE(type); } vshTablePrintToStdout(table, ctl); @@ -686,10 +682,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(source); - VIR_FREE(target); - VIR_FREE(device); - VIR_FREE(type); VIR_FREE(disks); return ret; } @@ -999,7 +991,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) virDomainBlockStatsStruct stats; virTypedParameterPtr params = NULL; virTypedParameterPtr par = NULL; - char *value = NULL; const char *field = NULL; int rc, nparams = 0; size_t i; @@ -1065,6 +1056,8 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) /* at first print all known values in desired order */ for (i = 0; domblkstat_output[i].field != NULL; i++) { + g_autofree char *value = NULL; + if (!(par = virTypedParamsGet(params, nparams, domblkstat_output[i].field))) continue; @@ -1087,18 +1080,17 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s %-*s %s\n", device, human ? 31 : 0, field, value); - - VIR_FREE(value); } /* go through the fields again, for remaining fields */ for (i = 0; i < nparams; i++) { + g_autofree char *value = NULL; + if (!*params[i].field) continue; value = vshGetTypedParamValue(ctl, params+i); vshPrint(ctl, "%s %s %s\n", device, params[i].field, value); - VIR_FREE(value); } } @@ -1939,7 +1931,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool optName = vshCommandOptBool(cmd, "name"); bool optID = vshCommandOptBool(cmd, "id"); size_t i; - char *title; char uuid[VIR_UUID_STRING_BUFLEN]; int state; bool ret = false; @@ -2022,6 +2013,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) state = -2; if (optTitle) { + g_autofree char *title = NULL; + if (!(title = virshGetDomainDescription(ctl, dom, true, 0))) goto cleanup; if (vshTableRowAppend(table, id_buf, @@ -2030,7 +2023,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd) : virshDomainStateToString(state), title, NULL) < 0) goto cleanup; - VIR_FREE(title); } else { if (vshTableRowAppend(table, id_buf, virDomainGetName(dom), @@ -2187,7 +2179,6 @@ virshDomainStatsPrintRecord(vshControl *ctl G_GNUC_UNUSED, virDomainStatsRecordPtr record, bool raw G_GNUC_UNUSED) { - char *param; size_t i; vshPrint(ctl, "Domain: '%s'\n", virDomainGetName(record->dom)); @@ -2195,12 +2186,12 @@ virshDomainStatsPrintRecord(vshControl *ctl G_GNUC_UNUSED, /* XXX: Implement pretty-printing */ for (i = 0; i < record->nparams; i++) { + g_autofree char *param = NULL; + if (!(param = vshGetTypedParamValue(ctl, record->params + i))) return false; vshPrint(ctl, " %s=%s\n", record->params[i].field, param); - - VIR_FREE(param); } return true; @@ -2400,7 +2391,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < ifaces_count; i++) { virDomainInterfacePtr iface = ifaces[i]; - char *ip_addr_str = NULL; const char *type = NULL; if (ifacestr && STRNEQ(ifacestr, iface->name)) @@ -2416,6 +2406,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) for (j = 0; j < iface->naddrs; j++) { g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + g_autofree char *ip_addr_str = NULL; switch (iface->addrs[j].type) { case VIR_IP_ADDR_TYPE_IPV4: @@ -2443,8 +2434,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, " %-10s %-17s %s\n", "-", "-", ip_addr_str); - - VIR_FREE(ip_addr_str); } } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f72ec36f6f..542e2a1736 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3055,7 +3055,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *iface; const char *state; - char *value; virMacAddr macaddr; const char *element; const char *attr; @@ -3119,13 +3118,10 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) while (cur) { if (cur->type == XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, element)) { - value = virXMLPropString(cur, attr); + g_autofree char *value = virXMLPropString(cur, attr); - if (STRCASEEQ(value, iface)) { - VIR_FREE(value); + if (STRCASEEQ(value, iface)) goto hit; - } - VIR_FREE(value); } cur = cur->next; } @@ -3639,9 +3635,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */ int nvol_nodes; - char *source = NULL; - char *target = NULL; - char *pool = NULL; size_t i; size_t j; virshControl *priv = ctl->privData; @@ -3759,14 +3752,13 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) goto error; for (i = 0; i < nvol_nodes; i++) { + g_autofree char *source = NULL; + g_autofree char *target = NULL; + g_autofree char *pool = NULL; virshUndefineVolume vol; ctxt->node = vol_nodes[i]; - VIR_FREE(source); - VIR_FREE(target); - VIR_FREE(pool); - /* get volume source and target paths */ if (!(target = virXPathString("string(./target/@dev)", ctxt))) goto error; @@ -3936,9 +3928,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(source); - VIR_FREE(target); - VIR_FREE(pool); for (i = 0; i < nvols; i++) { VIR_FREE(vols[i].source); VIR_FREE(vols[i].target); @@ -5096,7 +5085,6 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, virTypedParameterPtr src_params, int nsrc_params, virTypedParameterPtr *update_params) { - char *set_field = NULL; char *set_val = NULL; const char *val = NULL; const vshCmdOpt *opt = NULL; @@ -5107,7 +5095,8 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, int rv; while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { - set_field = g_strdup(opt->data); + g_autofree char *set_field = g_strdup(opt->data); + if (!(set_val = strchr(set_field, '='))) { vshError(ctl, "%s", _("Invalid syntax for --set, " "expecting name=value")); @@ -5121,8 +5110,6 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, ¶ms, &nparams, &maxparams, set_field, set_val) < 0) goto cleanup; - - VIR_FREE(set_field); } rv = vshCommandOptStringReq(ctl, cmd, "cap", &val); @@ -5145,7 +5132,6 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, *update_params = g_steal_pointer(¶ms); cleanup: - VIR_FREE(set_field); virTypedParamsFree(params, nparams); return ret; } @@ -6759,7 +6745,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, unsigned int curvcpus = 0; unsigned int maxvcpus = 0; unsigned int vcpuid; - char *online = NULL; if (inactive) flags |= VIR_DOMAIN_XML_INACTIVE; @@ -6788,6 +6773,8 @@ virshDomainGetVcpuBitmap(vshControl *ctl, } for (i = 0; i < nnodes; i++) { + g_autofree char *online = NULL; + ctxt->node = nodes[i]; if (virXPathUInt("string(@id)", ctxt, &vcpuid) < 0 || @@ -6796,8 +6783,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (STREQ(online, "yes")) ignore_value(virBitmapSetBit(ret, vcpuid)); - - VIR_FREE(online); } if (virBitmapCountBits(ret) != curvcpus) { @@ -6807,7 +6792,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, } cleanup: - VIR_FREE(online); VIR_FREE(nodes); return ret; } -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 11 +++-------- tools/virsh-host.c | 3 +-- tools/virsh-nodedev.c | 6 ++---- tools/virsh-pool.c | 4 +--- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 542e2a1736..0636bbfa31 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4002,7 +4002,7 @@ cmdStartGetFDs(vshControl *ctl, int **fdsret) { const char *fdopt; - char **fdlist = NULL; + g_auto(GStrv) fdlist = NULL; int *fds = NULL; size_t nfds = 0; size_t i; @@ -4028,14 +4028,11 @@ cmdStartGetFDs(vshControl *ctl, fds[nfds - 1] = fd; } - g_strfreev(fdlist); - *fdsret = fds; *nfdsret = nfds; return 0; error: - g_strfreev(fdlist); VIR_FREE(fds); return -1; } @@ -5859,7 +5856,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) const char *mode = NULL; int flags = 0; int rv; - char **modes = NULL; + g_auto(GStrv) modes = NULL; char **tmp; if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) @@ -5908,7 +5905,6 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - g_strfreev(modes); return ret; } @@ -5943,7 +5939,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) const char *name; const char *mode = NULL; int flags = 0; - char **modes = NULL; + g_auto(GStrv) modes = NULL; char **tmp; if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) @@ -5988,7 +5984,6 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - g_strfreev(modes); return ret; } diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a07f5adbfa..df1fe49e09 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1301,7 +1301,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = false; char *result = NULL; - char **list = NULL; + g_auto(GStrv) list = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; @@ -1326,7 +1326,6 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(result); - g_strfreev(list); return ret; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5b1afe4601..c6c7d97d50 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -115,7 +115,7 @@ static virNodeDevice* vshFindNodeDevice(vshControl *ctl, const char *value) { virNodeDevicePtr dev = NULL; - char **arr = NULL; + g_auto(GStrv) arr = NULL; int narr; virshControl *priv = ctl->privData; @@ -140,7 +140,6 @@ vshFindNodeDevice(vshControl *ctl, const char *value) } cleanup: - g_strfreev(arr); return dev; } @@ -409,7 +408,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) bool tree = vshCommandOptBool(cmd, "tree"); bool ret = true; unsigned int flags = 0; - char **caps = NULL; + g_auto(GStrv) caps = NULL; int ncaps = 0; struct virshNodeDeviceList *list = NULL; int cap_type = -1; @@ -555,7 +554,6 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } cleanup: - g_strfreev(caps); virshNodeDeviceListFree(list); return ret; } diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 5bce5cf06c..03987770f6 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1175,7 +1175,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) if (type) { int poolType = -1; - char **poolTypes = NULL; + g_auto(GStrv) poolTypes = NULL; int npoolTypes = 0; if ((npoolTypes = vshStringToArray(type, &poolTypes)) < 0) @@ -1184,7 +1184,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) for (i = 0; i < npoolTypes; i++) { if ((poolType = virStoragePoolTypeFromString(poolTypes[i])) < 0) { vshError(ctl, _("Invalid pool type '%s'"), poolTypes[i]); - g_strfreev(poolTypes); return false; } @@ -1235,7 +1234,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) break; } } - g_strfreev(poolTypes); } if (!(list = virshStoragePoolListCollect(ctl, flags))) -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 18 ++-- tools/virsh-domain.c | 168 ++++++++++++----------------------- tools/virsh-host.c | 92 ++++++------------- tools/virsh-interface.c | 6 +- tools/virsh-network.c | 15 ++-- tools/virsh-nodedev.c | 14 +-- tools/virsh-nwfilter.c | 9 +- tools/virsh-pool.c | 27 ++---- tools/virsh-secret.c | 6 +- tools/virsh-util.c | 3 +- tools/virsh-volume.c | 18 ++-- tools/virsh.c | 3 +- 12 files changed, 122 insertions(+), 257 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index b07959b1ee..49f632f11b 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -595,7 +595,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int ndisks; - xmlNodePtr *disks = NULL; + g_autofree xmlNodePtr *disks = NULL; size_t i; bool details = false; g_autoptr(vshTable) table = NULL; @@ -682,7 +682,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(disks); return ret; } @@ -712,7 +711,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; int ninterfaces; - xmlNodePtr *interfaces = NULL; + g_autofree xmlNodePtr *interfaces = NULL; size_t i; g_autoptr(vshTable) table = NULL; @@ -766,7 +765,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(interfaces); return ret; } @@ -803,13 +801,13 @@ static bool cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) { const char *iface = NULL; - char *state = NULL; - char *xpath = NULL; + g_autofree char *state = NULL; + g_autofree char *xpath = NULL; virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] = ""; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlNodePtr *interfaces = NULL; + g_autofree xmlNodePtr *interfaces = NULL; int ninterfaces; unsigned int flags = 0; bool ret = false; @@ -858,9 +856,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(state); - VIR_FREE(interfaces); - VIR_FREE(xpath); return ret; } @@ -989,7 +984,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *name = NULL, *device = NULL; virDomainBlockStatsStruct stats; - virTypedParameterPtr params = NULL; + g_autofree virTypedParameterPtr params = NULL; virTypedParameterPtr par = NULL; const char *field = NULL; int rc, nparams = 0; @@ -1097,7 +1092,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(params); return ret; } #undef DOMBLKSTAT_LEGACY_PRINT diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0636bbfa31..0b536b75dd 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -890,7 +890,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) int ret; bool functionReturn = false; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - char *xml = NULL; + g_autofree char *xml = NULL; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -1072,7 +1072,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(xml); return functionReturn; } @@ -1424,9 +1423,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) } for (i = 0; i < nparams; i++) { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } else { if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0) @@ -1619,9 +1617,8 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) } for (i = 0; i < nparams; i++) { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } else { /* set the blkio parameters */ @@ -3067,7 +3064,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathObject) obj = NULL; xmlNodePtr cur = NULL; - char *xml_buf = NULL; + g_autofree char *xml_buf = NULL; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -3174,7 +3171,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(xml_buf); return ret; } @@ -3352,9 +3348,8 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) } for (i = 0; i < nparams; i++) { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } else { if (virDomainSetInterfaceParameters(dom, device, params, @@ -4048,7 +4043,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) unsigned int flags = VIR_DOMAIN_NONE; int rc; size_t nfds = 0; - int *fds = NULL; + g_autofree int *fds = NULL; if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, VIRSH_BYNAME | VIRSH_BYUUID))) @@ -4115,7 +4110,6 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(fds); return ret; } @@ -4169,7 +4163,7 @@ doSave(void *opaque) const char *to = NULL; unsigned int flags = 0; const char *xmlfile = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; #ifndef WIN32 sigset_t sigmask, oldsigmask; @@ -4215,7 +4209,6 @@ doSave(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: #endif /* !WIN32 */ - VIR_FREE(xml); g_main_loop_quit(data->eventLoop); } @@ -4494,7 +4487,7 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) const char *file = NULL; bool ret = false; unsigned int flags = 0; - char *xml = NULL; + g_autofree char *xml = NULL; virshControl *priv = ctl->privData; if (vshCommandOptBool(cmd, "security-info")) @@ -4511,7 +4504,6 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); return ret; } @@ -4552,7 +4544,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) const char *file = NULL; bool ret = false; const char *xmlfile = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; @@ -4579,7 +4571,6 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); return ret; } @@ -4918,7 +4909,7 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) bool ret = false; g_autoptr(virshDomain) dom = NULL; unsigned int flags = 0; - char *xml = NULL; + g_autofree char *xml = NULL; if (vshCommandOptBool(cmd, "security-info")) flags |= VIR_DOMAIN_XML_SECURE; @@ -4933,7 +4924,6 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); return ret; } @@ -4974,7 +4964,7 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) bool ret = false; g_autoptr(virshDomain) dom = NULL; const char *xmlfile = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; unsigned int flags = 0; if (vshCommandOptBool(cmd, "running")) @@ -5004,7 +4994,6 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); return ret; } @@ -5278,7 +5267,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) bool ret = false; unsigned int flags = 0; const char *xmlfile = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -5309,7 +5298,6 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); return ret; } @@ -6702,7 +6690,7 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, int maxcpu, bool pretty) { - char *str = NULL; + g_autofree char *str = NULL; size_t i; int ret = -1; @@ -6720,7 +6708,6 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, ret = 0; cleanup: - VIR_FREE(str); return ret; } @@ -6734,7 +6721,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, virBitmap *ret = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *nodes = NULL; int nnodes; size_t i; unsigned int curvcpus = 0; @@ -6787,7 +6774,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, } cleanup: - VIR_FREE(nodes); return ret; } @@ -6937,13 +6923,12 @@ virshPrintPinInfo(vshControl *ctl, unsigned char *cpumap, size_t cpumaplen) { - char *str = NULL; + g_autofree char *str = NULL; if (!(str = virBitmapDataFormat(cpumap, cpumaplen))) return false; vshPrint(ctl, "%s", str); - VIR_FREE(str); return true; } @@ -6956,7 +6941,7 @@ virshVcpuPinQuery(vshControl *ctl, int maxcpu, unsigned int flags) { - unsigned char *cpumap = NULL; + g_autofree unsigned char *cpumap = NULL; unsigned int countFlags = flags | VIR_DOMAIN_VCPU_MAXIMUM; int cpumaplen; size_t i; @@ -7017,7 +7002,6 @@ virshVcpuPinQuery(vshControl *ctl, ret = true; cleanup: - VIR_FREE(cpumap); return ret; } @@ -7063,7 +7047,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) unsigned int vcpu = 0; const char *cpulist = NULL; bool ret = false; - unsigned char *cpumap = NULL; + g_autofree unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; bool config = vshCommandOptBool(cmd, "config"); @@ -7123,7 +7107,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(cpumap); return ret; } @@ -7160,7 +7143,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *cpulist = NULL; bool ret = false; - unsigned char *cpumap = NULL; + g_autofree unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; bool config = vshCommandOptBool(cmd, "config"); @@ -7225,7 +7208,6 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(cpumap); return ret; } @@ -7680,7 +7662,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) unsigned int iothread_id = 0; int maxcpu; bool ret = false; - unsigned char *cpumap = NULL; + g_autofree unsigned char *cpumap = NULL; int cpumaplen; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; virshControl *priv = ctl->privData; @@ -7715,7 +7697,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(cpumap); return ret; } @@ -7996,9 +7977,8 @@ vshCPUStatsPrintField(vshControl *ctl, param->value.ul / 1000000000, param->value.ul % 1000000000); } else { - char *s = vshGetTypedParamValue(ctl, param); + g_autofree char *s = vshGetTypedParamValue(ctl, param); vshPrint(ctl, "%s\n", s); - VIR_FREE(s); } } @@ -8180,13 +8160,13 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *from = NULL; bool ret = false; - char *buffer; + g_autofree char *buffer = NULL; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); #endif unsigned int flags = 0; size_t nfds = 0; - int *fds = NULL; + g_autofree int *fds = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -8224,8 +8204,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(buffer); - VIR_FREE(fds); return ret; } @@ -8623,14 +8601,13 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, "%s\n", _("Metadata modified")); } else { - char *data; + g_autofree char *data = NULL; /* get */ if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, flags))) goto cleanup; vshPrint(ctl, "%s\n", data); - VIR_FREE(data); } ret = true; @@ -9172,9 +9149,8 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) { vshPrint(ctl, "%-15s: %s\n", params[i].field, _("unlimited")); } else { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } } else { @@ -9441,9 +9417,8 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) vshPrint(ctl, "%-15s: %s\n", params[i].field, virDomainNumatuneMemModeTypeToString(params[i].value.i)); } else { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-15s: %s\n", params[i].field, str); - VIR_FREE(str); } } } else { @@ -9587,7 +9562,7 @@ virshEventQemuPrint(virConnectPtr conn G_GNUC_UNUSED, { virshQemuEventData *data = opaque; virJSONValue *pretty = NULL; - char *str = NULL; + g_autofree char *str = NULL; if (!data->loop && data->count) return; @@ -9613,8 +9588,6 @@ virshEventQemuPrint(virConnectPtr conn G_GNUC_UNUSED, data->count++; if (!data->loop) vshEventDone(data->ctl); - - VIR_FREE(str); } static const vshCmdInfo info_qemu_monitor_event[] = { @@ -9917,15 +9890,15 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; bool ret = false; const vshCmdOpt *opt = NULL; - char **cmdargv = NULL; + g_autofree char **cmdargv = NULL; size_t ncmdargv = 0; pid_t pid; int nfdlist; int *fdlist; size_t i; bool setlabel = true; - virSecurityModelPtr secmodel = NULL; - virSecurityLabelPtr seclabel = NULL; + g_autofree virSecurityModelPtr secmodel = NULL; + g_autofree virSecurityLabelPtr seclabel = NULL; virshControl *priv = ctl->privData; dom = virshCommandOptDomain(ctl, cmd, NULL); @@ -10007,9 +9980,6 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(seclabel); - VIR_FREE(secmodel); - VIR_FREE(cmdargv); return ret; } @@ -10052,7 +10022,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; bool ret = true; - char *dump; + g_autofree char *dump = NULL; unsigned int flags = 0; bool inactive = vshCommandOptBool(cmd, "inactive"); bool secure = vshCommandOptBool(cmd, "security-info"); @@ -10074,7 +10044,6 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) dump = virDomainGetXMLDesc(dom, flags); if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } @@ -10115,8 +10084,8 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd) bool ret = true; const char *format = NULL; const char *configFile = NULL; - char *configData; - char *xmlData; + g_autofree char *configData = NULL; + g_autofree char *xmlData = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; @@ -10130,12 +10099,10 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd) xmlData = virConnectDomainXMLFromNative(priv->conn, format, configData, flags); if (xmlData != NULL) { vshPrint(ctl, "%s", xmlData); - VIR_FREE(xmlData); } else { ret = false; } - VIR_FREE(configData); return ret; } @@ -10172,8 +10139,8 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) bool ret = false; const char *format = NULL; const char *xmlFile = NULL; - char *configData = NULL; - char *xmlData = NULL; + g_autofree char *configData = NULL; + g_autofree char *xmlData = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; g_autoptr(virshDomain) dom = NULL; @@ -10211,8 +10178,6 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(xmlData); - VIR_FREE(configData); return ret; } @@ -11615,7 +11580,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; bool ret = false; int port = 0; - char *listen_addr = NULL; + g_autofree char *listen_addr = NULL; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -11658,7 +11623,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(listen_addr); return ret; } @@ -11686,7 +11650,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; bool ret = false; - char *tty = NULL; + g_autofree char *tty = NULL; if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; @@ -11698,7 +11662,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(tty); return ret; } @@ -11947,7 +11910,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *from = NULL; - char *buffer = NULL; + g_autofree char *buffer = NULL; bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); @@ -11992,7 +11955,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(buffer); return ret; } @@ -12042,7 +12004,7 @@ virshDomainDetachInterface(char *doc, g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL, matchNode = NULL; - char *detach_xml = NULL; + g_autofree char *detach_xml = NULL; char buf[64]; int diff_mac, ret = -1; size_t i; @@ -12077,9 +12039,8 @@ virshDomainDetachInterface(char *doc, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, "mac")) { - char *tmp_mac = virXMLPropString(cur, "address"); + g_autofree char *tmp_mac = virXMLPropString(cur, "address"); diff_mac = virMacAddrCompare(tmp_mac, mac); - VIR_FREE(tmp_mac); if (!diff_mac) { if (matchNode) { /* this is the 2nd match, so it's ambiguous */ @@ -12112,7 +12073,6 @@ virshDomainDetachInterface(char *doc, ret = virDomainDetachDevice(dom, detach_xml); cleanup: - VIR_FREE(detach_xml); return ret == 0; } @@ -12121,7 +12081,8 @@ static bool cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - char *doc_live = NULL, *doc_config = NULL; + g_autofree char *doc_live = NULL; + g_autofree char *doc_config = NULL; const char *mac = NULL, *type = NULL; int flags = 0; bool ret = false, affect_config, affect_live; @@ -12176,8 +12137,6 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) } else { vshPrintExtra(ctl, "%s", _("Interface detached successfully\n")); } - VIR_FREE(doc_live); - VIR_FREE(doc_config); return ret; } @@ -12248,13 +12207,11 @@ virshFindDisk(const char *doc, /* Check if the disk is CDROM or floppy disk */ if (virXMLNodeNameEqual(n, "disk")) { - char *device_value = virXMLPropString(n, "device"); + g_autofree char *device_value = virXMLPropString(n, "device"); if (STREQ(device_value, "cdrom") || STREQ(device_value, "floppy")) is_supported = true; - - VIR_FREE(device_value); } if (!is_supported) @@ -12264,7 +12221,7 @@ virshFindDisk(const char *doc, cur = obj->nodesetval->nodeTab[i]->children; while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { - char *tmp = NULL; + g_autofree char *tmp = NULL; if (virXMLNodeNameEqual(cur, "source")) { if ((tmp = virXMLPropString(cur, "file")) || @@ -12280,10 +12237,8 @@ virshFindDisk(const char *doc, ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); /* drop backing store since they are not needed here */ virshDiskDropBackingStore(ret); - VIR_FREE(tmp); goto cleanup; } - VIR_FREE(tmp); } cur = cur->next; } @@ -12317,10 +12272,10 @@ virshUpdateDiskXML(xmlNodePtr disk_node, xmlNodePtr source = NULL; xmlNodePtr target_node = NULL; xmlNodePtr text_node = NULL; - char *device_type = NULL; + g_autofree char *device_type = NULL; char *ret = NULL; - char *startupPolicy = NULL; - char *source_path = NULL; + g_autofree char *startupPolicy = NULL; + g_autofree char *source_path = NULL; if (!disk_node) return NULL; @@ -12436,9 +12391,6 @@ virshUpdateDiskXML(xmlNodePtr disk_node, } cleanup: - VIR_FREE(device_type); - VIR_FREE(startupPolicy); - VIR_FREE(source_path); return ret; } @@ -12478,10 +12430,10 @@ static const vshCmdOptDef opts_detach_disk[] = { static bool cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) { - char *disk_xml = NULL; + g_autofree char *disk_xml = NULL; g_autoptr(virshDomain) dom = NULL; const char *target = NULL; - char *doc = NULL; + g_autofree char *doc = NULL; int ret; bool functionReturn = false; xmlNodePtr disk_node = NULL; @@ -12548,8 +12500,6 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) cleanup: xmlFreeNode(disk_node); - VIR_FREE(disk_xml); - VIR_FREE(doc); return functionReturn; } @@ -13225,16 +13175,13 @@ virshEventJobCompletedPrint(virConnectPtr conn G_GNUC_UNUSED, { g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; size_t i; - char *value; virBufferAsprintf(&buf, _("event 'job-completed' for domain '%s':\n"), virDomainGetName(dom)); for (i = 0; i < nparams; i++) { - value = virTypedParameterToString(¶ms[i]); - if (value) { + g_autofree char *value = virTypedParameterToString(¶ms[i]); + if (value) virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); - VIR_FREE(value); - } } virshEventPrint(opaque, &buf); } @@ -13611,9 +13558,9 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *source = NULL; const char *path = NULL; - char *doc = NULL; + g_autofree char *doc = NULL; xmlNodePtr disk_node = NULL; - char *disk_xml = NULL; + g_autofree char *disk_xml = NULL; bool ret = false; virshUpdateDiskXMLType update_type; const char *action = NULL; @@ -13705,9 +13652,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(doc); xmlFreeNode(disk_node); - VIR_FREE(disk_xml); return ret; } @@ -13789,7 +13734,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; int ret = -1; const vshCmdOpt *opt = NULL; - const char **mountpoints = NULL; + g_autofree const char **mountpoints = NULL; size_t nmountpoints = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) @@ -13809,7 +13754,6 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), ret); cleanup: - VIR_FREE(mountpoints); return ret >= 0; } @@ -13838,7 +13782,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; int ret = -1; const vshCmdOpt *opt = NULL; - const char **mountpoints = NULL; + g_autofree const char **mountpoints = NULL; size_t nmountpoints = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) @@ -13858,7 +13802,6 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), ret); cleanup: - VIR_FREE(mountpoints); return ret >= 0; } @@ -14060,9 +14003,8 @@ cmdGuestInfo(vshControl *ctl, const vshCmd *cmd) goto cleanup; for (i = 0; i < nparams; i++) { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "%-20s: %s\n", params[i].field, str); - VIR_FREE(str); } ret = true; diff --git a/tools/virsh-host.c b/tools/virsh-host.c index df1fe49e09..a32af023ae 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -49,7 +49,7 @@ static const vshCmdInfo info_capabilities[] = { static bool cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - char *caps; + g_autofree char *caps = NULL; virshControl *priv = ctl->privData; if ((caps = virConnectGetCapabilities(priv->conn)) == NULL) { @@ -57,7 +57,6 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) return false; } vshPrint(ctl, "%s\n", caps); - VIR_FREE(caps); return true; } @@ -99,7 +98,7 @@ static bool cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) { bool ret = false; - char *caps = NULL; + g_autofree char *caps = NULL; const char *virttype = NULL; const char *emulatorbin = NULL; const char *arch = NULL; @@ -123,7 +122,6 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", caps); ret = true; cleanup: - VIR_FREE(caps); return ret; } @@ -159,14 +157,14 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) bool ret = false; int cell = -1; unsigned long long memory = 0; - xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *nodes = NULL; unsigned long nodes_cnt; - unsigned long *nodes_id = NULL; - unsigned long long *nodes_free = NULL; + g_autofree unsigned long *nodes_id = NULL; + g_autofree unsigned long long *nodes_free = NULL; bool all = vshCommandOptBool(cmd, "all"); bool cellno = vshCommandOptBool(cmd, "cellno"); size_t i; - char *cap_xml = NULL; + g_autofree char *cap_xml = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; @@ -202,13 +200,11 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < nodes_cnt; i++) { unsigned long id; - char *val = virXMLPropString(nodes[i], "id"); + g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - VIR_FREE(val); goto cleanup; } - VIR_FREE(val); nodes_id[i] = id; if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]), id, 1) != 1) { @@ -243,10 +239,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(nodes); - VIR_FREE(nodes_free); - VIR_FREE(nodes_id); - VIR_FREE(cap_xml); return ret; } @@ -296,15 +288,15 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) { bool ret = false; unsigned int npages; - unsigned int *pagesize = NULL; + g_autofree unsigned int *pagesize = NULL; unsigned long long bytes = 0; unsigned int kibibytes = 0; int cell; - unsigned long long *counts = NULL; + g_autofree unsigned long long *counts = NULL; size_t i, j; xmlNodePtr *nodes = NULL; int nodes_cnt; - char *cap_xml = NULL; + g_autofree char *cap_xml = NULL; g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; bool all = vshCommandOptBool(cmd, "all"); @@ -347,15 +339,12 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) pagesize = g_new0(unsigned int, nodes_cnt); for (i = 0; i < nodes_cnt; i++) { - char *val = virXMLPropString(nodes[i], "size"); + g_autofree char *val = virXMLPropString(nodes[i], "size"); if (virStrToLong_uip(val, NULL, 10, &pagesize[i]) < 0) { vshError(ctl, _("unable to parse page size: %s"), val); - VIR_FREE(val); goto cleanup; } - - VIR_FREE(val); } /* Here, if we've done the trick few lines above, @@ -387,14 +376,12 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell", ctxt, &nodes); for (i = 0; i < nodes_cnt; i++) { - char *val = virXMLPropString(nodes[i], "id"); + g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_i(val, NULL, 10, &cell) < 0) { vshError(ctl, _("unable to parse numa node id: %s"), val); - VIR_FREE(val); goto cleanup; } - VIR_FREE(val); if (virNodeGetFreePages(priv->conn, npages, pagesize, cell, 1, counts, 0) < 0) @@ -441,10 +428,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(cap_xml); VIR_FREE(nodes); - VIR_FREE(counts); - VIR_FREE(pagesize); return ret; } @@ -501,10 +485,10 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) unsigned int pageSizes[1]; unsigned long long pageCounts[1], tmp; unsigned int flags = 0; - char *cap_xml = NULL; + g_autofree char *cap_xml = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *nodes = NULL; virshControl *priv = ctl->privData; VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); @@ -547,13 +531,11 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < nodes_cnt; i++) { unsigned long id; - char *val = virXMLPropString(nodes[i], "id"); + g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - VIR_FREE(val); goto cleanup; } - VIR_FREE(val); if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts, id, 1, flags) < 0) @@ -567,8 +549,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(nodes); - VIR_FREE(cap_xml); return ret; } @@ -599,7 +579,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) { const char *type = NULL; int vcpus = -1; - char *caps = NULL; + g_autofree char *caps = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; @@ -625,7 +605,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(caps); return ret; } @@ -691,7 +670,7 @@ static bool cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { int cpu, cpunum; - unsigned char *cpumap = NULL; + g_autofree unsigned char *cpumap = NULL; unsigned int online; bool pretty = vshCommandOptBool(cmd, "pretty"); bool ret = false; @@ -708,12 +687,11 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) vshPrint(ctl, "%-15s ", _("CPU map:")); if (pretty) { - char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum)); + g_autofree char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum)); if (!str) goto cleanup; vshPrint(ctl, "%s", str); - VIR_FREE(str); } else { for (cpu = 0; cpu < cpunum; cpu++) vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-'); @@ -723,7 +701,6 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) ret = true; cleanup: - VIR_FREE(cpumap); return ret; } @@ -788,7 +765,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) size_t i, j; bool flag_percent = vshCommandOptBool(cmd, "percent"); int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; - virNodeCPUStatsPtr params; + g_autofree virNodeCPUStatsPtr params = NULL; int nparams = 0; bool ret = false; unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 }; @@ -871,7 +848,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(params); return ret; } @@ -902,7 +878,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) int nparams = 0; size_t i; int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; - virNodeMemoryStatsPtr params = NULL; + g_autofree virNodeMemoryStatsPtr params = NULL; bool ret = false; virshControl *priv = ctl->privData; @@ -935,7 +911,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(params); return ret; } @@ -1023,7 +998,7 @@ static const vshCmdInfo info_sysinfo[] = { static bool cmdSysinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - char *sysinfo; + g_autofree char *sysinfo = NULL; virshControl *priv = ctl->privData; sysinfo = virConnectGetSysinfo(priv->conn, 0); @@ -1033,7 +1008,6 @@ cmdSysinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } vshPrint(ctl, "%s", sysinfo); - VIR_FREE(sysinfo); return true; } @@ -1054,7 +1028,7 @@ static const vshCmdInfo info_hostname[] = { static bool cmdHostname(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - char *hostname; + g_autofree char *hostname = NULL; virshControl *priv = ctl->privData; hostname = virConnectGetHostname(priv->conn); @@ -1064,7 +1038,6 @@ cmdHostname(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } vshPrint(ctl, "%s\n", hostname); - VIR_FREE(hostname); return true; } @@ -1085,7 +1058,7 @@ static const vshCmdInfo info_uri[] = { static bool cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - char *uri; + g_autofree char *uri = NULL; virshControl *priv = ctl->privData; uri = virConnectGetURI(priv->conn); @@ -1095,7 +1068,6 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } vshPrint(ctl, "%s\n", uri); - VIR_FREE(uri); return true; } @@ -1114,11 +1086,11 @@ vshExtractCPUDefXMLs(vshControl *ctl, const char *xmlFile) { char **cpus = NULL; - char *buffer = NULL; - char *xmlStr = NULL; + g_autofree char *buffer = NULL; + g_autofree char *xmlStr = NULL; g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *nodes = NULL; char *doc; size_t i; int n; @@ -1177,9 +1149,6 @@ vshExtractCPUDefXMLs(vshControl *ctl, } cleanup: - VIR_FREE(buffer); - VIR_FREE(xmlStr); - VIR_FREE(nodes); return cpus; error: @@ -1300,7 +1269,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) { const char *from = NULL; bool ret = false; - char *result = NULL; + g_autofree char *result = NULL; g_auto(GStrv) list = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; @@ -1325,7 +1294,6 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) ret = true; } - VIR_FREE(result); return ret; } @@ -1577,9 +1545,8 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) */ vshPrint(ctl, _("Shared memory:\n")); for (i = 0; i < nparams; i++) { - char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + g_autofree char *str = vshGetTypedParamValue(ctl, ¶ms[i]); vshPrint(ctl, "\t%-15s %s\n", params[i].field, str); - VIR_FREE(str); } } else { if (virNodeSetMemoryParameters(priv->conn, params, nparams, flags) != 0) @@ -1766,7 +1733,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl, const char *arch = NULL; const char *machine = NULL; bool ret = false; - char *result = NULL; + g_autofree char *result = NULL; char **list = NULL; unsigned int flags = 0; virshControl *priv = ctl->privData; @@ -1797,7 +1764,6 @@ cmdHypervisorCPUBaseline(vshControl *ctl, ret = true; } - VIR_FREE(result); g_strfreev(list); return ret; } diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index f88ec188f1..07d5f50be3 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -486,7 +486,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) { virInterfacePtr iface; bool ret = true; - char *dump; + g_autofree char *dump = NULL; unsigned int flags = 0; bool inactive = vshCommandOptBool(cmd, "inactive"); @@ -499,7 +499,6 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) dump = virInterfaceGetXMLDesc(iface, flags); if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } @@ -533,7 +532,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) virInterfacePtr iface; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -543,7 +542,6 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) return false; iface = virInterfaceDefineXML(priv->conn, buffer, 0); - VIR_FREE(buffer); if (iface != NULL) { vshPrintExtra(ctl, _("Interface %s defined from %s\n"), diff --git a/tools/virsh-network.c b/tools/virsh-network.c index d641606dde..0d61e20093 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -206,7 +206,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) virNetworkPtr network; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -216,7 +216,6 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) return false; network = virNetworkCreateXML(priv->conn, buffer); - VIR_FREE(buffer); if (network != NULL) { vshPrintExtra(ctl, _("Network %s created from %s\n"), @@ -254,7 +253,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) virNetworkPtr network; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -264,7 +263,6 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) return false; network = virNetworkDefineXML(priv->conn, buffer); - VIR_FREE(buffer); if (network != NULL) { vshPrintExtra(ctl, _("Network %s defined from %s\n"), @@ -343,7 +341,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) { virNetworkPtr network; bool ret = true; - char *dump; + g_autofree char *dump = NULL; unsigned int flags = 0; int inactive; @@ -358,7 +356,6 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } @@ -964,7 +961,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) const char *sectionStr = NULL; int command, section, parentIndex = -1; const char *xml = NULL; - char *xmlFromFile = NULL; + g_autofree char *xmlFromFile = NULL; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); unsigned int flags = VIR_NETWORK_UPDATE_AFFECT_CURRENT; @@ -1059,7 +1056,6 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) cleanup: vshReportError(ctl); virNetworkFree(network); - VIR_FREE(xmlFromFile); return ret; } @@ -1556,7 +1552,7 @@ cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd) virNetworkPtr network; virNetworkPortPtr port = NULL; bool ret = true; - char *dump; + g_autofree char *dump = NULL; unsigned int flags = 0; if (!(network = virshCommandOptNetwork(ctl, cmd, NULL))) @@ -1569,7 +1565,6 @@ cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd) if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c6c7d97d50..c4b1d556ca 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -58,7 +58,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) virNodeDevicePtr dev = NULL; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -68,7 +68,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) return false; dev = virNodeDeviceCreateXML(priv->conn, buffer, 0); - VIR_FREE(buffer); if (dev != NULL) { vshPrintExtra(ctl, _("Node device %s created from %s\n"), @@ -293,7 +292,7 @@ virshNodeDeviceListCollect(vshControl *ctl, /* filter the list if the list was acquired by fallback means */ for (i = 0; i < list->ndevices; i++) { - char **caps = NULL; + g_autofree char **caps = NULL; int ncaps = 0; bool match = false; size_t j, k; @@ -310,7 +309,6 @@ virshNodeDeviceListCollect(vshControl *ctl, if ((ncaps = virNodeDeviceListCaps(device, caps, ncaps)) < 0) { vshError(ctl, "%s", _("Failed to get capability names of the device")); - VIR_FREE(caps); goto cleanup; } @@ -326,8 +324,6 @@ virshNodeDeviceListCollect(vshControl *ctl, } } - VIR_FREE(caps); - if (!match) goto remove_entry; @@ -586,7 +582,7 @@ static bool cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) { virNodeDevicePtr device = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; const char *device_value = NULL; bool ret = false; @@ -605,7 +601,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(xml); if (device) virNodeDeviceFree(device); return ret; @@ -1084,7 +1079,7 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) virNodeDevice *dev = NULL; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -1094,7 +1089,6 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) return false; dev = virNodeDeviceDefineXML(priv->conn, buffer, 0); - VIR_FREE(buffer); if (dev != NULL) { vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"), diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index acb35e8aa1..f38f33798d 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -90,7 +90,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) virNWFilterPtr nwfilter; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -100,7 +100,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) return false; nwfilter = virNWFilterDefineXML(priv->conn, buffer); - VIR_FREE(buffer); if (nwfilter != NULL) { vshPrintExtra(ctl, _("Network filter %s defined from %s\n"), @@ -185,7 +184,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) { virNWFilterPtr nwfilter; bool ret = true; - char *dump; + g_autofree char *dump = NULL; if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL))) return false; @@ -193,7 +192,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) dump = virNWFilterGetXMLDesc(nwfilter, 0); if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } @@ -600,7 +598,7 @@ cmdNWFilterBindingDumpXML(vshControl *ctl, const vshCmd *cmd) { virNWFilterBindingPtr binding; bool ret = true; - char *dump; + g_autofree char *dump = NULL; if (!(binding = virshCommandOptNWFilterBinding(ctl, cmd, NULL))) return false; @@ -608,7 +606,6 @@ cmdNWFilterBindingDumpXML(vshControl *ctl, const vshCmd *cmd) dump = virNWFilterBindingGetXMLDesc(binding, 0); if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 03987770f6..f0ee95bdf8 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -270,7 +270,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; bool build; bool overwrite; bool no_overwrite; @@ -298,7 +298,6 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) return false; pool = virStoragePoolCreateXML(priv->conn, buffer, flags); - VIR_FREE(buffer); if (pool != NULL) { vshPrintExtra(ctl, _("Pool %s created from %s\n"), @@ -464,7 +463,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; const char *name; - char *xml; + g_autofree char *xml = NULL; bool printXML = vshCommandOptBool(cmd, "print-xml"); bool build; bool overwrite; @@ -491,10 +490,8 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) if (printXML) { vshPrint(ctl, "%s", xml); - VIR_FREE(xml); } else { pool = virStoragePoolCreateXML(priv->conn, xml, flags); - VIR_FREE(xml); if (pool != NULL) { vshPrintExtra(ctl, _("Pool %s created\n"), name); @@ -533,7 +530,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool; const char *from = NULL; bool ret = true; - char *buffer; + g_autofree char *buffer = NULL; virshControl *priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) @@ -543,7 +540,6 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) return false; pool = virStoragePoolDefineXML(priv->conn, buffer, 0); - VIR_FREE(buffer); if (pool != NULL) { vshPrintExtra(ctl, _("Pool %s defined from %s\n"), @@ -574,7 +570,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; const char *name; - char *xml; + g_autofree char *xml = NULL; bool printXML = vshCommandOptBool(cmd, "print-xml"); virshControl *priv = ctl->privData; @@ -583,10 +579,8 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) if (printXML) { vshPrint(ctl, "%s", xml); - VIR_FREE(xml); } else { pool = virStoragePoolDefineXML(priv->conn, xml, 0); - VIR_FREE(xml); if (pool != NULL) { vshPrintExtra(ctl, _("Pool %s defined\n"), name); @@ -799,7 +793,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) bool ret = true; bool inactive = vshCommandOptBool(cmd, "inactive"); unsigned int flags = 0; - char *dump; + g_autofree char *dump = NULL; if (inactive) flags |= VIR_STORAGE_XML_INACTIVE; @@ -810,7 +804,6 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) dump = virStoragePoolGetXMLDesc(pool, flags); if (dump != NULL) { vshPrint(ctl, "%s", dump); - VIR_FREE(dump); } else { ret = false; } @@ -1442,8 +1435,8 @@ static bool cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED) { const char *type = NULL, *host = NULL; - char *srcSpec = NULL; - char *srcList; + g_autofree char *srcSpec = NULL; + g_autofree char *srcList = NULL; const char *initiator = NULL; virshControl *priv = ctl->privData; @@ -1479,13 +1472,11 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED) } srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0); - VIR_FREE(srcSpec); if (srcList == NULL) { vshError(ctl, _("Failed to find any %s pool sources"), type); return false; } vshPrint(ctl, "%s", srcList); - VIR_FREE(srcList); return true; } @@ -1832,7 +1823,7 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr pool = NULL; virStoragePoolPtr pool_edited = NULL; unsigned int flags = VIR_STORAGE_XML_INACTIVE; - char *tmp_desc = NULL; + g_autofree char *tmp_desc = NULL; virshControl *priv = ctl->privData; pool = virshCommandOptPool(ctl, cmd, "pool", NULL); @@ -1847,8 +1838,6 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) } else { goto cleanup; } - } else { - VIR_FREE(tmp_desc); } #define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 4f433fae9c..dde0d26398 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -80,7 +80,7 @@ static bool cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) { const char *from = NULL; - char *buffer; + g_autofree char *buffer = NULL; virSecretPtr res; char uuid[VIR_UUID_STRING_BUFLEN]; bool ret = false; @@ -106,7 +106,6 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(buffer); virshSecretFree(res); return ret; } @@ -139,7 +138,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd) { virSecretPtr secret; bool ret = false; - char *xml; + g_autofree char *xml = NULL; secret = virshCommandOptSecret(ctl, cmd, NULL); if (secret == NULL) @@ -149,7 +148,6 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd) if (xml == NULL) goto cleanup; vshPrint(ctl, "%s", xml); - VIR_FREE(xml); ret = true; cleanup: diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 97b8f4d5c3..19cd0bcb99 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -304,7 +304,7 @@ virshDomainGetXMLFromDom(vshControl *ctl, xmlDocPtr *xml, xmlXPathContextPtr *ctxt) { - char *desc = NULL; + g_autofree char *desc = NULL; if (!(desc = virDomainGetXMLDesc(dom, flags))) { vshError(ctl, _("Failed to get domain description xml")); @@ -312,7 +312,6 @@ virshDomainGetXMLFromDom(vshControl *ctl, } *xml = virXMLParseStringCtxt(desc, _("(domain_definition)"), ctxt); - VIR_FREE(desc); if (!(*xml)) { vshError(ctl, _("Failed to parse domain description xml")); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index af93998d57..b4dfcc2f7a 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -233,7 +233,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) { virStoragePoolPtr pool; virStorageVolPtr vol = NULL; - char *xml = NULL; + g_autofree char *xml = NULL; bool printXML = vshCommandOptBool(cmd, "print-xml"); const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL; const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL; @@ -290,7 +290,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) /* Convert the snapshot parameters into backingStore XML */ if (snapshotStrVol) { virStorageVolPtr snapVol; - char *snapshotStrVolPath; + g_autofree char *snapshotStrVolPath = NULL; /* Lookup snapshot backing volume. Try the backing-vol * parameter as a name */ vshDebug(ctl, VSH_ERR_DEBUG, @@ -347,7 +347,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) virBufferAddLit(&buf, "</backingStore>\n"); /* Cleanup snapshot allocations */ - VIR_FREE(snapshotStrVolPath); virStorageVolFree(snapVol); } @@ -372,7 +371,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) if (vol) virStorageVolFree(vol); virStoragePoolFree(pool); - VIR_FREE(xml); return ret; } @@ -407,7 +405,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = false; unsigned int flags = 0; - char *buffer = NULL; + g_autofree char *buffer = NULL; if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; @@ -433,7 +431,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(buffer); virStoragePoolFree(pool); return ret; } @@ -477,7 +474,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) virStorageVolPtr newvol = NULL, inputvol = NULL; const char *from = NULL; bool ret = false; - char *buffer = NULL; + g_autofree char *buffer = NULL; unsigned int flags = 0; if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL))) @@ -512,7 +509,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(buffer); if (pool) virStoragePoolFree(pool); if (inputvol) @@ -585,7 +581,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) virStoragePoolPtr origpool = NULL; virStorageVolPtr origvol = NULL, newvol = NULL; const char *name = NULL; - char *origxml = NULL; + g_autofree char *origxml = NULL; xmlChar *newxml = NULL; bool ret = false; unsigned int flags = 0; @@ -632,7 +628,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - VIR_FREE(origxml); xmlFree(newxml); if (origvol) virStorageVolFree(origvol); @@ -1680,7 +1675,7 @@ static bool cmdVolPath(vshControl *ctl, const vshCmd *cmd) { virStorageVolPtr vol; - char * StorageVolPath; + g_autofree char *StorageVolPath = NULL; if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; @@ -1691,7 +1686,6 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) } vshPrint(ctl, "%s\n", StorageVolPath); - VIR_FREE(StorageVolPath); virStorageVolFree(vol); return true; } diff --git a/tools/virsh.c b/tools/virsh.c index fc27cb529e..ce5fd247dd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -81,7 +81,7 @@ virshCatchDisconnect(virConnectPtr conn, vshControl *ctl = opaque; const char *str = "unknown reason"; virErrorPtr error; - char *uri; + g_autofree char *uri = NULL; virErrorPreserveLast(&error); uri = virConnectGetURI(conn); @@ -101,7 +101,6 @@ virshCatchDisconnect(virConnectPtr conn, break; } vshError(ctl, _(str), NULLSTR(uri)); - VIR_FREE(uri); virErrorRestore(&error); disconnected++; -- 2.31.1

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-completer-domain.c | 30 +- tools/virsh-domain-monitor.c | 128 +++---- tools/virsh-domain.c | 634 ++++++++++++--------------------- tools/virsh-host.c | 87 ++--- tools/virsh-nodedev.c | 7 +- tools/virsh-volume.c | 5 +- tools/vsh.c | 11 +- 7 files changed, 317 insertions(+), 585 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 471f9974a1..c86d8e8156 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -447,7 +447,6 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, g_autofree virDomainIOThreadInfoPtr *info = NULL; size_t i; int rc; - char **ret = NULL; g_auto(GStrv) tmp = NULL; virCheckFlags(0, NULL); @@ -456,7 +455,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, return NULL; if ((rc = virDomainGetIOThreadInfo(dom, &info, flags)) < 0) - goto cleanup; + return NULL; niothreads = rc; @@ -465,10 +464,7 @@ virshDomainIOThreadIdCompleter(vshControl *ctl, for (i = 0; i < niothreads; i++) tmp[i] = g_strdup_printf("%u", info[i]->iothread_id); - ret = g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } @@ -482,7 +478,6 @@ virshDomainVcpuCompleter(vshControl *ctl, g_autoptr(xmlXPathContext) ctxt = NULL; int nvcpus = 0; unsigned int id; - char **ret = NULL; g_auto(GStrv) tmp = NULL; virCheckFlags(0, NULL); @@ -492,21 +487,18 @@ virshDomainVcpuCompleter(vshControl *ctl, if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; tmp = g_new0(char *, nvcpus + 1); for (id = 0; id < nvcpus; id++) tmp[id] = g_strdup_printf("%u", id); - ret = g_steal_pointer(&tmp); - - cleanup: - return ret; + return g_steal_pointer(&tmp); } @@ -522,7 +514,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, unsigned int id; g_auto(GStrv) vcpulist = NULL; const char *vcpuid = NULL; - char **ret = NULL; virCheckFlags(0, NULL); @@ -530,25 +521,22 @@ virshDomainVcpulistCompleter(vshControl *ctl, return NULL; if (vshCommandOptStringQuiet(ctl, cmd, "vcpulist", &vcpuid) < 0) - goto cleanup; + return NULL; if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE, &xml, &ctxt) < 0) - goto cleanup; + return NULL; /* Query the max rather than the current vcpu count */ if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0) - goto cleanup; + return NULL; vcpulist = g_new0(char *, nvcpus + 1); for (id = 0; id < nvcpus; id++) vcpulist[id] = g_strdup_printf("%u", id); - ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist); - - cleanup: - return ret; + return virshCommaStringListComplete(vcpuid, (const char **)vcpulist); } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 49f632f11b..d5e9ad3bce 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -81,7 +81,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, /* fall back to xml */ if (virshDomainGetXMLFromDom(ctl, dom, flags, &doc, &ctxt) < 0) - goto cleanup; + return NULL; if (title) desc = virXPathString("string(./title[1])", ctxt); @@ -91,8 +91,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, if (!desc) desc = g_strdup(""); - cleanup: - return desc; } @@ -299,7 +297,6 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; unsigned int nr_stats; size_t i; - bool ret = false; int rv = 0; int period = -1; bool config = vshCommandOptBool(cmd, "config"); @@ -326,26 +323,25 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) * This is not really an unsigned long, but it */ if ((rv = vshCommandOptInt(ctl, cmd, "period", &period)) < 0) - goto cleanup; + return false; if (rv > 0) { if (period < 0) { vshError(ctl, _("Invalid collection period value '%d'"), period); - goto cleanup; + return false; } if (virDomainSetMemoryStatsPeriod(dom, period, flags) < 0) { vshError(ctl, "%s", _("Unable to change balloon collection period.")); - } else { - ret = true; + return false; } - goto cleanup; + return true; } nr_stats = virDomainMemoryStats(dom, stats, VIR_DOMAIN_MEMORY_STAT_NR, 0); if (nr_stats == -1) { vshError(ctl, _("Failed to get memory statistics for domain %s"), name); - goto cleanup; + return false; } for (i = 0; i < nr_stats; i++) { @@ -377,9 +373,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "hugetlb_pgfail %llu\n", stats[i].val); } - ret = true; - cleanup: - return ret; + return true; } /* @@ -590,7 +584,6 @@ static const vshCmdOptDef opts_domblklist[] = { static bool cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; unsigned int flags = 0; g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; @@ -606,11 +599,11 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) details = vshCommandOptBool(cmd, "details"); if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto cleanup; + return false; if (details) table = vshTableNew(_("Type"), _("Device"), _("Target"), _("Source"), NULL); @@ -618,7 +611,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) table = vshTableNew(_("Target"), _("Source"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ndisks; i++) { g_autofree char *type = NULL; @@ -633,14 +626,14 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) device = virXPathString("string(./@device)", ctxt); if (!type || !device) { vshPrint(ctl, "unable to query block list details"); - goto cleanup; + return false; } } target = virXPathString("string(./target/@dev)", ctxt); if (!target) { vshError(ctl, "unable to query block list"); - goto cleanup; + return false; } if (STREQ_NULLABLE(type, "nvme")) { @@ -652,7 +645,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) !(addrNode = virXPathNode("./source/address", ctxt)) || virPCIDeviceAddressParseXML(addrNode, &addr) < 0) { vshError(ctl, "Unable to query NVMe disk address"); - goto cleanup; + return false; } source = g_strdup_printf("nvme://%04x:%02x:%02x.%d/%s", @@ -669,20 +662,17 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) if (details) { if (vshTableRowAppend(table, type, device, target, NULLSTR_MINUS(source), NULL) < 0) - goto cleanup; + return false; } else { if (vshTableRowAppend(table, target, NULLSTR_MINUS(source), NULL) < 0) - goto cleanup; + return false; } } vshTablePrintToStdout(table, ctl); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -706,7 +696,6 @@ static const vshCmdOptDef opts_domiflist[] = { static bool cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; unsigned int flags = 0; g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; @@ -719,16 +708,16 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXML(ctl, cmd, flags, &xmldoc, &ctxt) < 0) - goto cleanup; + return false; ninterfaces = virXPathNodeSet("./devices/interface", ctxt, &interfaces); if (ninterfaces < 0) - goto cleanup; + return false; table = vshTableNew(_("Interface"), _("Type"), _("Source"), _("Model"), _("MAC"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ninterfaces; i++) { g_autofree char *type = NULL; @@ -757,15 +746,12 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) model ? model : "-", mac ? mac : "-", NULL) < 0) - goto cleanup; + return false; } vshTablePrintToStdout(table, ctl); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -810,7 +796,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) g_autofree xmlNodePtr *interfaces = NULL; int ninterfaces; unsigned int flags = 0; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) return false; @@ -819,7 +804,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) flags = VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - goto cleanup; + return false; /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) == 0) @@ -831,7 +816,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) { vshError(ctl, _("Failed to extract interface information")); - goto cleanup; + return false; } if (ninterfaces < 1) { @@ -840,10 +825,10 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, _("Interface (dev: %s) not found."), iface); - goto cleanup; + return false; } else if (ninterfaces > 1) { vshError(ctl, _("multiple matching interfaces found")); - goto cleanup; + return false; } ctxt->node = interfaces[0]; @@ -853,11 +838,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s up", iface); - ret = true; - - cleanup: - - return ret; + return true; } /* @@ -882,16 +863,13 @@ static bool cmdDomControl(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = true; virDomainControlInfo info; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if (virDomainGetControlInfo(dom, &info, 0) < 0) { - ret = false; - goto cleanup; - } + if (virDomainGetControlInfo(dom, &info, 0) < 0) + return false; if (info.state != VIR_DOMAIN_CONTROL_OK && info.state != VIR_DOMAIN_CONTROL_ERROR) { @@ -907,8 +885,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) virshDomainControlStateToString(info.state)); } - cleanup: - return ret; + return true; } /* @@ -989,7 +966,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) const char *field = NULL; int rc, nparams = 0; size_t i; - bool ret = false; bool human = vshCommandOptBool(cmd, "human"); /* human readable output */ if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -1000,7 +976,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) API contract. */ if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0) - goto cleanup; + return false; if (!device) device = ""; @@ -1014,7 +990,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) if (rc < 0) { /* try older API if newer is not supported */ if (last_error->code != VIR_ERR_NO_SUPPORT) - goto cleanup; + return false; vshResetLibvirtError(); @@ -1022,7 +998,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) sizeof(stats)) == -1) { vshError(ctl, _("Failed to get block stats %s %s"), name, device); - goto cleanup; + return false; } /* human friendly output */ @@ -1040,7 +1016,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) params = g_new0(virTypedParameter, nparams); if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) { vshError(ctl, _("Failed to get block stats for domain '%s' device '%s'"), name, device); - goto cleanup; + return false; } /* set for prettier output */ @@ -1089,10 +1065,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - - cleanup: - return ret; + return true; } #undef DOMBLKSTAT_LEGACY_PRINT @@ -1126,17 +1099,16 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *name = NULL, *device = NULL; virDomainInterfaceStatsStruct stats; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) return false; if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0) - goto cleanup; + return false; if (virDomainInterfaceStats(dom, device, &stats, sizeof(stats)) == -1) { vshError(ctl, _("Failed to get interface stats %s %s"), name, device); - goto cleanup; + return false; } if (stats.rx_bytes >= 0) @@ -1163,10 +1135,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) if (stats.tx_drop >= 0) vshPrint(ctl, "%s tx_drop %lld\n", device, stats.tx_drop); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -1398,17 +1367,14 @@ static bool cmdDomstate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = true; bool showReason = vshCommandOptBool(cmd, "reason"); int state, reason; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; - if ((state = virshDomainState(ctl, dom, &reason)) < 0) { - ret = false; - goto cleanup; - } + if ((state = virshDomainState(ctl, dom, &reason)) < 0) + return false; if (showReason) { vshPrint(ctl, "%s (%s)\n", @@ -1419,8 +1385,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) virshDomainStateToString(state)); } - cleanup: - return ret; + return true; } /* @@ -1461,7 +1426,6 @@ static bool cmdDomTime(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool now = vshCommandOptBool(cmd, "now"); bool pretty = vshCommandOptBool(cmd, "pretty"); bool rtcSync = vshCommandOptBool(cmd, "sync"); @@ -1482,7 +1446,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { /* invalid integer format */ - goto cleanup; + return false; } else if (rv > 0) { /* valid integer to set */ doSet = true; @@ -1491,18 +1455,18 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) if (doSet || now || rtcSync) { if (now && ((seconds = time(NULL)) == (time_t) -1)) { vshError(ctl, _("Unable to get current time")); - goto cleanup; + return false; } if (rtcSync) flags |= VIR_DOMAIN_TIME_SYNC; if (virDomainSetTime(dom, seconds, nseconds, flags) < 0) - goto cleanup; + return false; } else { if (virDomainGetTime(dom, &seconds, &nseconds, flags) < 0) - goto cleanup; + return false; if (pretty) { g_autoptr(GDateTime) then = NULL; @@ -1517,9 +1481,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - cleanup: - return ret; + return true; } /* diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0b536b75dd..d06c24cc74 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -325,7 +325,6 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; char *buffer; int rv; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -346,7 +345,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -354,7 +353,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } if (flags || current) @@ -366,14 +365,11 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) if (rv < 0) { vshError(ctl, _("Failed to attach device from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", _("Device attached successfully\n")); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -888,7 +884,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virNetDevBandwidthRate inbound, outbound; virDomainNetType typ; int ret; - bool functionReturn = false; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autofree char *xml = NULL; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -917,35 +912,35 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 || vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0) - goto cleanup; + return false; /* check interface type */ if ((int)(typ = virDomainNetTypeFromString(type)) < 0) { vshError(ctl, _("No support for %s in command 'attach-interface'"), type); - goto cleanup; + return false; } if (inboundStr) { memset(&inbound, 0, sizeof(inbound)); if (virshParseRateStr(ctl, inboundStr, &inbound) < 0) - goto cleanup; + return false; if (!inbound.average && !inbound.floor) { vshError(ctl, _("either inbound average or floor is mandatory")); - goto cleanup; + return false; } } if (outboundStr) { memset(&outbound, 0, sizeof(outbound)); if (virshParseRateStr(ctl, outboundStr, &outbound) < 0) - goto cleanup; + return false; if (outbound.average == 0) { vshError(ctl, _("outbound average is mandatory")); - goto cleanup; + return false; } if (outbound.floor) { vshError(ctl, _("outbound floor is unsupported yet")); - goto cleanup; + return false; } } @@ -975,7 +970,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (virshAddressParse(pciaddrstr, false, &addr) < 0) { vshError(ctl, _("cannot parse pci address '%s' for network interface"), source); - goto cleanup; + return false; } virBufferAddLit(&buf, "<source>\n"); @@ -998,7 +993,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) case VIR_DOMAIN_NET_TYPE_LAST: vshError(ctl, _("No support for %s in command 'attach-interface'"), type); - goto cleanup; + return false; break; } @@ -1048,12 +1043,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "print-xml")) { vshPrint(ctl, "%s", xml); - functionReturn = true; - goto cleanup; + return true; } if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -1066,13 +1060,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) if (ret != 0) { vshError(ctl, "%s", _("Failed to attach interface")); - } else { - vshPrintExtra(ctl, "%s", _("Interface attached successfully\n")); - functionReturn = true; + return false; } - cleanup: - return functionReturn; + vshPrintExtra(ctl, "%s", _("Interface attached successfully\n")); + return true; } /* @@ -2690,11 +2682,11 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async); if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; /* XXX Allow path to be optional to list info on all devices at once */ if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) - goto cleanup; + return false; if (bandwidth) ret = virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes); @@ -2703,7 +2695,6 @@ cmdBlockjob(vshControl *ctl, const vshCmd *cmd) else ret = virshBlockJobInfo(ctl, dom, path, raw, bytes); - cleanup: return ret; } @@ -2987,7 +2978,6 @@ static bool cmdConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool force = vshCommandOptBool(cmd, "force"); bool safe = vshCommandOptBool(cmd, "safe"); unsigned int flags = 0; @@ -2997,17 +2987,14 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "devname", &name) < 0) /* sc_prohibit_devname */ - goto cleanup; + return false; if (force) flags |= VIR_DOMAIN_CONSOLE_FORCE; if (safe) flags |= VIR_DOMAIN_CONSOLE_SAFE; - ret = cmdRunConsole(ctl, dom, name, flags); - - cleanup: - return ret; + return cmdRunConsole(ctl, dom, name, flags); } #endif /* WIN32 */ @@ -3056,7 +3043,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) const char *element; const char *attr; bool config; - bool ret = false; unsigned int flags = 0; unsigned int xmlflags = 0; size_t i; @@ -3071,13 +3057,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0 || vshCommandOptStringReq(ctl, cmd, "state", &state) < 0) - goto cleanup; + return false; config = vshCommandOptBool(cmd, "config"); if (STRNEQ(state, "up") && STRNEQ(state, "down")) { vshError(ctl, _("invalid link state '%s'"), state); - goto cleanup; + return false; } if (config) { @@ -3091,13 +3077,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) flags = VIR_DOMAIN_AFFECT_CONFIG; if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0) - goto cleanup; + return false; obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt); if (obj == NULL || obj->type != XPATH_NODESET || obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) { vshError(ctl, _("Failed to extract interface information or no interfaces found")); - goto cleanup; + return false; } if (virMacAddrParse(iface, &macaddr) == 0) { @@ -3125,7 +3111,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } vshError(ctl, _("interface (%s: %s) not found"), element, iface); - goto cleanup; + return false; hit: /* find and modify/add link state node */ @@ -3150,29 +3136,25 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) BAD_CAST "link", NULL); if (!cur) - goto cleanup; + return false; if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) == NULL) - goto cleanup; + return false; } if (!(xml_buf = virXMLNodeToString(xml, obj->nodesetval->nodeTab[i]))) { vshSaveLibvirtError(); vshError(ctl, _("Failed to create XML")); - goto cleanup; + return false; } if (virDomainUpdateDeviceFlags(dom, xml_buf, flags) < 0) { vshError(ctl, _("Failed to update interface link state")); - goto cleanup; - } else { - vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); - ret = true; + return false; } - cleanup: - - return ret; + vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); + return true; } /* "domiftune" command @@ -3447,7 +3429,6 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; const char *target = NULL; int suspendTarget; unsigned long long duration = 0; @@ -3456,29 +3437,26 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptULongLong(ctl, cmd, "duration", &duration) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) - goto cleanup; + return false; if ((suspendTarget = virshNodeSuspendTargetTypeFromString(target)) < 0) { vshError(ctl, "%s", _("Invalid target")); - goto cleanup; + return false; } if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0) { vshError(ctl, _("Domain '%s' could not be suspended"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' successfully suspended"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -3506,7 +3484,6 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; unsigned int flags = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -3515,16 +3492,13 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) if (virDomainPMWakeup(dom, flags) < 0) { vshError(ctl, _("Domain '%s' could not be woken up"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' successfully woken up"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4036,7 +4010,6 @@ static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); #endif @@ -4051,11 +4024,11 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (virDomainGetID(dom) != (unsigned int)-1) { vshError(ctl, "%s", _("Domain is already active")); - goto cleanup; + return false; } if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; @@ -4075,7 +4048,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (last_error->code != VIR_ERR_NO_SUPPORT && last_error->code != VIR_ERR_INVALID_ARG) { vshReportError(ctl); - goto cleanup; + return false; } vshResetLibvirtError(); rc = virDomainHasManagedSaveImage(dom, 0); @@ -4085,7 +4058,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) } else if (rc > 0) { if (virDomainManagedSaveRemove(dom, 0) < 0) { vshReportError(ctl); - goto cleanup; + return false; } } flags &= ~VIR_DOMAIN_START_FORCE_BOOT; @@ -4096,7 +4069,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) (flags ? virDomainCreateWithFlags(dom, flags) : virDomainCreate(dom))) < 0) { vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(dom)); - goto cleanup; + return false; } started: @@ -4104,13 +4077,10 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) virDomainGetName(dom)); #ifndef WIN32 if (console && !cmdRunConsole(ctl, dom, NULL, 0)) - goto cleanup; + return false; #endif - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4485,7 +4455,6 @@ static bool cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) { const char *file = NULL; - bool ret = false; unsigned int flags = 0; g_autofree char *xml = NULL; virshControl *priv = ctl->privData; @@ -4498,13 +4467,10 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd) xml = virDomainSaveImageGetXMLDesc(priv->conn, file, flags); if (!xml) - goto cleanup; + return false; vshPrint(ctl, "%s", xml); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4542,7 +4508,6 @@ static bool cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) { const char *file = NULL; - bool ret = false; const char *xmlfile = NULL; g_autofree char *xml = NULL; unsigned int flags = 0; @@ -4560,18 +4525,15 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) return false; if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; if (virDomainSaveImageDefineXML(priv->conn, file, xml, flags) < 0) { vshError(ctl, _("Failed to update %s"), file); - goto cleanup; + return false; } vshPrintExtra(ctl, _("State file %s updated.\n"), file); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4785,7 +4747,6 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *name; - bool ret = false; int hassave; if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) @@ -4794,14 +4755,14 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) hassave = virDomainHasManagedSaveImage(dom, 0); if (hassave < 0) { vshError(ctl, "%s", _("Failed to check for domain managed save image")); - goto cleanup; + return false; } if (hassave) { if (virDomainManagedSaveRemove(dom, 0) < 0) { vshError(ctl, _("Failed to remove managed save image for domain '%s'"), name); - goto cleanup; + return false; } else vshPrintExtra(ctl, _("Removed managedsave image for domain '%s'"), name); @@ -4810,10 +4771,7 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%s' has no manage save image; removal skipped"), name); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4859,7 +4817,7 @@ cmdManagedSaveEdit(vshControl *ctl, const vshCmd *cmd) dom = virshCommandOptDomain(ctl, cmd, NULL); if (dom == NULL) - goto cleanup; + return false; #define EDIT_GET_XML virDomainManagedSaveGetXMLDesc(dom, getxml_flags) #define EDIT_NOT_CHANGED \ @@ -4906,7 +4864,6 @@ static const vshCmdOptDef opts_managed_save_dumpxml[] = { static bool cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autoptr(virshDomain) dom = NULL; unsigned int flags = 0; g_autofree char *xml = NULL; @@ -4915,16 +4872,13 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_XML_SECURE; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (!(xml = virDomainManagedSaveGetXMLDesc(dom, flags))) - goto cleanup; + return false; vshPrint(ctl, "%s", xml); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -4961,7 +4915,6 @@ static const vshCmdOptDef opts_managed_save_define[] = { static bool cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autoptr(virshDomain) dom = NULL; const char *xmlfile = NULL; g_autofree char *xml = NULL; @@ -4981,20 +4934,17 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd) return false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (virDomainManagedSaveDefineXML(dom, xml, flags) < 0) { vshError(ctl, _("Failed to update %s XML configuration"), virDomainGetName(dom)); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Managed save state file of domain '%s' updated.\n"), virDomainGetName(dom)); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -5264,7 +5214,6 @@ static bool cmdRestore(vshControl *ctl, const vshCmd *cmd) { const char *from = NULL; - bool ret = false; unsigned int flags = 0; const char *xmlfile = NULL; g_autofree char *xml = NULL; @@ -5285,20 +5234,17 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) if (xmlfile && virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) - goto cleanup; + return false; if (((flags || xml) ? virDomainRestoreFlags(priv->conn, from, xml, flags) : virDomainRestore(priv->conn, from)) < 0) { vshError(ctl, _("Failed to restore domain from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain restored from %s\n"), from); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -5451,7 +5397,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "verbose")) verbose = true; @@ -5460,18 +5406,18 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) true, doDump, &data) < 0) - goto cleanup; + return false; virshWatchJob(ctl, dom, verbose, eventLoop, &data.ret, 0, NULL, NULL, _("Dump")); virThreadJoin(&workerThread); - if (!data.ret) - vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); + if (data.ret) + return false; - cleanup: - return !data.ret; + vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); + return true; } static const vshCmdInfo info_screenshot[] = { @@ -5751,7 +5697,6 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) const char *password = NULL; const char *user = NULL; unsigned int flags = 0; - bool ret = false; if (vshCommandOptBool(cmd, "encrypted")) flags = VIR_DOMAIN_PASSWORD_ENCRYPTED; @@ -5766,13 +5711,10 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) return false; if (virDomainSetUserPassword(dom, user, password, flags) < 0) - goto cleanup; + return false; vshPrintExtra(ctl, _("Password set successfully for %s in %s"), user, name); - ret = true; - - cleanup: - return ret; + return true; } /* * "resume" command @@ -5839,7 +5781,6 @@ static bool cmdShutdown(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *name; const char *mode = NULL; int flags = 0; @@ -5872,13 +5813,13 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Unknown mode %s value, expecting " "'acpi', 'agent', 'initctl', 'signal', " "or 'paravirt'"), mode); - goto cleanup; + return false; } tmp++; } if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; if (flags) rv = virDomainShutdownFlags(dom, flags); @@ -5888,12 +5829,10 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%s' is being shutdown\n"), name); } else { vshError(ctl, _("Failed to shutdown domain '%s'"), name); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -5923,7 +5862,6 @@ static bool cmdReboot(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *name; const char *mode = NULL; int flags = 0; @@ -5955,24 +5893,22 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Unknown mode %s value, expecting " "'acpi', 'agent', 'initctl', 'signal' " "or 'paravirt'"), mode); - goto cleanup; + return false; } tmp++; } if (!(dom = virshCommandOptDomain(ctl, cmd, &name))) - goto cleanup; + return false; if (virDomainReboot(dom, flags) == 0) { vshPrintExtra(ctl, _("Domain '%s' is being rebooted\n"), name); } else { vshError(ctl, _("Failed to reboot domain '%s'"), name); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -6586,7 +6522,6 @@ static bool cmdVcpucount(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); bool active = vshCommandOptBool(cmd, "active"); bool config = vshCommandOptBool(cmd, "config"); @@ -6636,7 +6571,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) VIR_DOMAIN_AFFECT_LIVE, true); if (conf_max == -2 || conf_cur == -2 || live_max == -2 || live_cur == -2) - goto cleanup; + return false; #define PRINT_COUNT(VAR, WHICH, STATE) if (VAR > 0) \ vshPrint(ctl, "%-12s %-12s %3d\n", WHICH, STATE, VAR) @@ -6650,15 +6585,12 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) int count = virshCPUCountCollect(ctl, dom, flags, false); if (count < 0) - goto cleanup; + return false; vshPrint(ctl, "%d\n", count); } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -6692,12 +6624,11 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, { g_autofree char *str = NULL; size_t i; - int ret = -1; vshPrint(ctl, "%-15s ", _("CPU Affinity:")); if (pretty) { if (!(str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(maxcpu)))) - goto cleanup; + return -1; vshPrint(ctl, _("%s (out of %d)"), str, maxcpu); } else { for (i = 0; i < maxcpu; i++) @@ -6705,10 +6636,7 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, } vshPrint(ctl, "\n"); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -6732,11 +6660,11 @@ virshDomainGetVcpuBitmap(vshControl *ctl, flags |= VIR_DOMAIN_XML_INACTIVE; if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) - goto cleanup; + return NULL; if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) { vshError(ctl, "%s", _("Failed to retrieve maximum vcpu count")); - goto cleanup; + return NULL; } ignore_value(virXPathUInt("string(/domain/vcpu/@current)", ctxt, &curvcpus)); @@ -6751,7 +6679,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, for (i = 0; i < curvcpus; i++) ignore_value(virBitmapSetBit(ret, i)); - goto cleanup; + return NULL; } for (i = 0; i < nnodes; i++) { @@ -6770,10 +6698,9 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (virBitmapCountBits(ret) != curvcpus) { vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap")); virBitmapFree(ret); - ret = NULL; + return NULL; } - cleanup: return ret; } @@ -6946,7 +6873,6 @@ virshVcpuPinQuery(vshControl *ctl, int cpumaplen; size_t i; int ncpus; - bool ret = false; g_autoptr(vshTable) table = NULL; if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) { @@ -6956,7 +6882,7 @@ virshVcpuPinQuery(vshControl *ctl, else vshError(ctl, "%s", _("cannot get vcpupin for transient domain")); } - goto cleanup; + return false; } if (got_vcpu && vcpu >= ncpus) { @@ -6970,7 +6896,7 @@ virshVcpuPinQuery(vshControl *ctl, vshError(ctl, _("vcpu %d is out of range of persistent cpu count %d"), vcpu, ncpus); - goto cleanup; + return false; } cpumaplen = VIR_CPU_MAPLEN(maxcpu); @@ -6979,7 +6905,7 @@ virshVcpuPinQuery(vshControl *ctl, cpumaplen, flags)) >= 0) { table = vshTableNew(_("VCPU"), _("CPU Affinity"), NULL); if (!table) - goto cleanup; + return false; for (i = 0; i < ncpus; i++) { g_autofree char *pinInfo = NULL; @@ -6989,20 +6915,18 @@ virshVcpuPinQuery(vshControl *ctl, if (!(pinInfo = virBitmapDataFormat(VIR_GET_CPUMAP(cpumap, cpumaplen, i), cpumaplen))) - goto cleanup; + return false; vcpuStr = g_strdup_printf("%zu", i); if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0) - goto cleanup; + return false; } vshTablePrintToStdout(table, ctl); } - ret = true; - cleanup: - return ret; + return true; } @@ -7089,25 +7013,22 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) /* Query mode: show CPU affinity information then exit.*/ if (!cpulist) { ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags); - goto cleanup; + return false; } /* Pin mode: pinning specified vcpu to specified physical cpus */ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; /* use old API without any explicit flags */ if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) { if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0) - goto cleanup; + return false; } else { if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -7193,22 +7114,20 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = virshPrintPinInfo(ctl, cpumap, cpumaplen); vshPrint(ctl, "\n"); } - goto cleanup; + return false; } /* Pin mode: pinning emulator threads to specified physical cpus */ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; if (flags == -1) flags = VIR_DOMAIN_AFFECT_LIVE; if (virDomainPinEmulator(dom, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -7254,7 +7173,6 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned int count = 0; - bool ret = false; bool maximum = vshCommandOptBool(cmd, "maximum"); bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); @@ -7284,26 +7202,23 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0) - goto cleanup; + return false; if (count == 0) { vshError(ctl, _("Can't set 0 processors for a VM")); - goto cleanup; + return false; } /* none of the options were specified */ if (!current && flags == 0) { if (virDomainSetVcpus(dom, count) != 0) - goto cleanup; + return false; } else { if (virDomainSetVcpusFlags(dom, count, flags) < 0) - goto cleanup; + return false; } - ret = true; - - cleanup: - return ret; + return true; } @@ -7438,7 +7353,6 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) bool live = vshCommandOptBool(cmd, "live"); const char *vcpulist = NULL; int state = 0; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable); @@ -7466,12 +7380,9 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) state = 1; if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7511,7 +7422,6 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) unsigned long long threshold; const char *dev = NULL; g_autoptr(virshDomain) dom = NULL; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "dev", &dev)) return false; @@ -7524,12 +7434,9 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) return false; if (virDomainSetBlockThreshold(dom, dev, threshold, 0) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7661,7 +7568,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) bool current = vshCommandOptBool(cmd, "current"); unsigned int iothread_id = 0; int maxcpu; - bool ret = false; g_autofree unsigned char *cpumap = NULL; int cpumaplen; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; @@ -7679,25 +7585,22 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptUInt(ctl, cmd, "iothread", &iothread_id) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) - goto cleanup; + return false; if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0) - goto cleanup; + return false; if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false; if (virDomainPinIOThread(dom, iothread_id, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -7731,7 +7634,6 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -7749,19 +7651,16 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } if (virDomainAddIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } @@ -7900,7 +7799,6 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int iothread_id = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -7918,19 +7816,16 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptInt(ctl, cmd, "id", &iothread_id) < 0) - goto cleanup; + return false; if (iothread_id <= 0) { vshError(ctl, _("Invalid IOThread id value: '%d'"), iothread_id); - goto cleanup; + return false; } if (virDomainDelIOThread(dom, iothread_id, flags) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -8159,7 +8054,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *from = NULL; - bool ret = false; g_autofree char *buffer = NULL; #ifndef WIN32 bool console = vshCommandOptBool(cmd, "console"); @@ -8176,7 +8070,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) return false; if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "paused")) flags |= VIR_DOMAIN_START_PAUSED; @@ -8192,7 +8086,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (!dom) { vshError(ctl, _("Failed to create domain from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, _("Domain '%s' created from %s\n"), @@ -8201,10 +8095,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (console) cmdRunConsole(ctl, dom, NULL, 0); #endif - ret = true; - - cleanup: - return ret; + return true; } /* @@ -8567,18 +8458,18 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "uri", &uri) < 0 || vshCommandOptStringReq(ctl, cmd, "key", &key) < 0 || vshCommandOptStringReq(ctl, cmd, "set", &set) < 0) - goto cleanup; + return false; if ((set || edit) && !key) { vshError(ctl, "%s", _("namespace key is required when modifying metadata")); - goto cleanup; + return false; } if (set || rem) { if (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, set, key, uri, flags)) - goto cleanup; + return false; if (rem) vshPrintExtra(ctl, "%s\n", _("Metadata removed")); @@ -8605,7 +8496,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) /* get */ if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, uri, flags))) - goto cleanup; + return false; vshPrint(ctl, "%s\n", data); } @@ -8698,7 +8589,6 @@ static bool cmdSendKey(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const char *codeset_option; int codeset; unsigned int holdtime = 0; @@ -8714,7 +8604,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) codeset_option = "linux"; if (vshCommandOptUInt(ctl, cmd, "holdtime", &holdtime) < 0) - goto cleanup; + return false; /* The qnum codeset was originally called rfb, so we need to keep * accepting the old name for backwards compatibility reasons */ @@ -8724,19 +8614,19 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) codeset = virKeycodeSetTypeFromString(codeset_option); if (codeset < 0) { vshError(ctl, _("unknown codeset: '%s'"), codeset_option); - goto cleanup; + return false; } while ((opt = vshCommandOptArgv(ctl, cmd, opt))) { if (count == VIR_DOMAIN_SEND_KEY_MAX_KEYS) { vshError(ctl, _("too many keycodes")); - goto cleanup; + return false; } if ((keycode = virshKeyCodeGetInt(opt->data)) < 0) { if ((keycode = virKeycodeValueFromString(codeset, opt->data)) < 0) { vshError(ctl, _("invalid keycode: '%s'"), opt->data); - goto cleanup; + return false; } } @@ -8744,11 +8634,10 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) count++; } - if (!(virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0)) - ret = true; + if (virDomainSendKey(dom, codeset, holdtime, keycodes, count, 0) < 0) + return false; - cleanup: - return ret; + return true; } /* @@ -8882,7 +8771,6 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8911,15 +8799,13 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes = VIR_DIV_UP(bytes, 1024); if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -8959,7 +8845,6 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) unsigned long long bytes = 0; unsigned long long max; unsigned long kibibytes = 0; - bool ret = false; bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); bool current = vshCommandOptBool(cmd, "current"); @@ -8983,17 +8868,15 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) - goto cleanup; + return false; kibibytes = VIR_DIV_UP(bytes, 1024); if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } /* @@ -9888,7 +9771,6 @@ static bool cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; const vshCmdOpt *opt = NULL; g_autofree char **cmdargv = NULL; size_t ncmdargv = 0; @@ -9903,7 +9785,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) dom = virshCommandOptDomain(ctl, cmd, NULL); if (dom == NULL) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "noseclabel")) setlabel = false; @@ -9916,16 +9798,16 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) cmdargv[ncmdargv - 1] = NULL; if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0) - goto cleanup; + return false; if (setlabel) { secmodel = g_new0(virSecurityModel, 1); seclabel = g_new0(virSecurityLabel, 1); if (virNodeGetSecurityModel(priv->conn, secmodel) < 0) - goto cleanup; + return false; if (virDomainGetSecurityLabel(dom, seclabel) < 0) - goto cleanup; + return false; } /* Fork once because we don't want to affect @@ -9933,7 +9815,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) * can only be changed in single-threaded process */ if ((pid = virFork()) < 0) - goto cleanup; + return false; if (pid == 0) { int status; @@ -9973,14 +9855,11 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) VIR_FREE(fdlist); if (virProcessWait(pid, NULL, false) < 0) { vshReportError(ctl); - goto cleanup; + return false; } } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -10136,7 +10015,6 @@ static const vshCmdOptDef opts_domxmltonative[] = { static bool cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; const char *format = NULL; const char *xmlFile = NULL; g_autofree char *configData = NULL; @@ -10159,26 +10037,22 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) xmlData = virDomainGetXMLDesc(dom, flags); } else if (xmlFile) { if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0) - goto cleanup; + return false; } else { vshError(ctl, "%s", _("need either domain or domain XML")); - goto cleanup; + return false; } if (!xmlData) { vshError(ctl, "%s", _("failed to retrieve XML")); - goto cleanup; + return false; } - if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) { - goto cleanup; - } else { - vshPrint(ctl, "%s", configData); - ret = true; - } + if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) + return false; - cleanup: - return ret; + vshPrint(ctl, "%s", configData); + return true; } /* @@ -10246,22 +10120,18 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *new_name = NULL; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false; if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0) - goto cleanup; + return false; if (virDomainRename(dom, new_name, 0) < 0) - goto cleanup; + return false; vshPrintExtra(ctl, "Domain successfully renamed\n"); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11076,19 +10946,15 @@ cmdMigrateGetMaxDowntime(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned long long downtime; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (virDomainMigrateGetMaxDowntime(dom, &downtime, 0) < 0) - goto done; + return false; vshPrint(ctl, "%llu\n", downtime); - ret = true; - - done: - return ret; + return true; } @@ -11121,7 +10987,6 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; unsigned long long size = 0; - bool ret = false; const char *unit; double value; int rc; @@ -11131,21 +10996,19 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) rc = vshCommandOptULongLong(ctl, cmd, "size", &size); if (rc < 0) { - goto cleanup; + return false; } else if (rc != 0) { if (virDomainMigrateSetCompressionCache(dom, size, 0) < 0) - goto cleanup; + return false; } if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0) - goto cleanup; + return false; value = vshPrettyCapacity(size, &unit); vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit); - ret = true; - cleanup: - return ret; + return true; } /* @@ -11182,24 +11045,20 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth = 0; unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0) - goto done; + return false; if (vshCommandOptBool(cmd, "postcopy")) flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; if (virDomainMigrateSetMaxSpeed(dom, bandwidth, flags) < 0) - goto done; + return false; - ret = true; - - done: - return ret; + return true; } /* @@ -11230,7 +11089,6 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; unsigned long bandwidth; unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -11239,14 +11097,11 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_MIGRATE_MAX_SPEED_POSTCOPY; if (virDomainMigrateGetMaxSpeed(dom, &bandwidth, flags) < 0) - goto done; + return false; vshPrint(ctl, "%lu\n", bandwidth); - ret = true; - - done: - return ret; + return true; } /* @@ -11272,18 +11127,14 @@ static bool cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (virDomainMigrateStartPostCopy(dom, 0) < 0) - goto cleanup; + return false; - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11578,7 +11429,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(virshDomain) dom = NULL; - bool ret = false; int port = 0; g_autofree char *listen_addr = NULL; @@ -11588,17 +11438,17 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) /* Check if the domain is active and don't rely on -1 for this */ if (!virDomainIsActive(dom)) { vshError(ctl, _("Domain is not running")); - goto cleanup; + return false; } if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0) - goto cleanup; + return false; /* Get the VNC port */ if (virXPathInt("string(/domain/devices/graphics[@type='vnc']/@port)", ctxt, &port)) { vshError(ctl, _("Failed to get VNC port. Is this domain using VNC?")); - goto cleanup; + return false; } listen_addr = virXPathString("string(/domain/devices/graphics" @@ -11620,10 +11470,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) else vshPrint(ctl, "%s:%d\n", listen_addr, port-5900); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11649,20 +11496,16 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; - bool ret = false; g_autofree char *tty = NULL; if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) return false; if (!(tty = virXPathString("string(/domain/devices/console/@tty)", ctxt))) - goto cleanup; + return false; vshPrint(ctl, "%s\n", tty); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -11849,7 +11692,6 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) bool config = vshCommandOptBool(cmd, "config"); bool live = vshCommandOptBool(cmd, "live"); unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; - bool ret = false; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); @@ -11863,18 +11705,15 @@ cmdDetachDeviceAlias(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0) - goto cleanup; + return false; if (virDomainDetachDeviceAlias(dom, alias, flags) < 0) { vshError(ctl, _("Failed to detach device with alias %s"), alias); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", _("Device detach request sent successfully\n")); - ret = true; - - cleanup: - return ret; + return true; } @@ -11911,7 +11750,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; const char *from = NULL; g_autofree char *buffer = NULL; - bool ret = false; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; bool current = vshCommandOptBool(cmd, "current"); bool config = vshCommandOptBool(cmd, "config"); @@ -11932,7 +11770,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (persistent && virDomainIsActive(dom) == 1) @@ -11940,7 +11778,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); - goto cleanup; + return false; } if (vshCommandOptBool(cmd, "force")) @@ -11948,14 +11786,11 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) { vshError(ctl, _("Failed to update device from %s"), from); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -12179,13 +12014,12 @@ virshFindDisk(const char *doc, g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; xmlNodePtr cur = NULL; - xmlNodePtr ret = NULL; size_t i; xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt); if (!xml) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); @@ -12194,7 +12028,7 @@ virshFindDisk(const char *doc, obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) { vshError(NULL, "%s", _("Failed to get disk information")); - goto cleanup; + return NULL; } /* search disk using @path */ @@ -12234,10 +12068,10 @@ virshFindDisk(const char *doc, } if (STREQ_NULLABLE(tmp, path)) { - ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); + xmlNodePtr ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); /* drop backing store since they are not needed here */ virshDiskDropBackingStore(ret); - goto cleanup; + return ret; } } cur = cur->next; @@ -12245,9 +12079,7 @@ virshFindDisk(const char *doc, } vshError(NULL, _("No disk found whose source path or target is %s"), path); - - cleanup: - return ret; + return NULL; } typedef enum { @@ -12285,7 +12117,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (!(STREQ_NULLABLE(device_type, "cdrom") || STREQ_NULLABLE(device_type, "floppy"))) { vshError(NULL, _("The disk device '%s' is not removable"), target); - goto cleanup; + return NULL; } /* find the current source subelement */ @@ -12319,7 +12151,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (type == VIRSH_UPDATE_DISK_XML_EJECT) { if (!source) { vshError(NULL, _("The disk device '%s' doesn't have media"), target); - goto cleanup; + return NULL; } /* forcibly switch to empty file cdrom */ @@ -12327,7 +12159,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, new_source = NULL; } else if (!new_source) { vshError(NULL, _("New disk media source was not specified")); - goto cleanup; + return NULL; } if (source) { @@ -12339,7 +12171,7 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (source_path && type == VIRSH_UPDATE_DISK_XML_INSERT) { vshError(NULL, _("The disk device '%s' already has media"), target); - goto cleanup; + return NULL; } startupPolicy = virXMLPropString(source, "startupPolicy"); @@ -12387,10 +12219,9 @@ virshUpdateDiskXML(xmlNodePtr disk_node, if (!(ret = virXMLNodeToString(NULL, disk_node))) { vshSaveLibvirtError(); - goto cleanup; + return NULL; } - cleanup: return ret; } @@ -13684,29 +13515,25 @@ static bool cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; - bool ret = false; unsigned long long minimum = 0; const char *mountPoint = NULL; unsigned int flags = 0; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false; if (vshCommandOptULongLong(ctl, cmd, "minimum", &minimum) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "mountpoint", &mountPoint) < 0) - goto cleanup; + return false; if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) { vshError(ctl, _("Unable to invoke fstrim")); - goto cleanup; + return false; } - ret = true; - - cleanup: - return ret; + return true; } static const vshCmdInfo info_domfsfreeze[] = { @@ -13914,20 +13741,17 @@ cmdGuestAgentTimeout(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; int timeout = VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK; const unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptInt(ctl, cmd, "timeout", &timeout) < 0) - goto cleanup; + return false; if (virDomainAgentSetResponseTimeout(dom, timeout, flags) < 0) - goto cleanup; + return false; - ret = true; - cleanup: - return ret; + return true; } /* @@ -14047,25 +13871,22 @@ cmdGetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) int nkeys = 0; size_t i; const unsigned int flags = 0; - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; nkeys = virDomainAuthorizedSSHKeysGet(dom, user, &keys, flags); if (nkeys < 0) - goto cleanup; + return false; for (i = 0; i < nkeys; i++) { vshPrint(ctl, "%s", keys[i]); } - ret = true; - cleanup: - return ret; + return true; } @@ -14115,7 +13936,6 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) g_auto(GStrv) keys = NULL; int nkeys = 0; unsigned int flags = 0; - bool ret = false; VSH_REQUIRE_OPTION("remove", "file"); VSH_EXCLUSIVE_OPTIONS("reset", "remove"); @@ -14124,10 +13944,10 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "user", &user) < 0) - goto cleanup; + return false; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) - goto cleanup; + return false; if (vshCommandOptBool(cmd, "remove")) { flags |= VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE; @@ -14137,7 +13957,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) if (!from) { vshError(ctl, _("Option --file is required")); - goto cleanup; + return false; } } } @@ -14145,27 +13965,25 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cmd) if (from) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshSaveLibvirtError(); - goto cleanup; + return false; } if (!(keys = g_strsplit(buffer, "\n", -1))) - goto cleanup; + return false; nkeys = g_strv_length(keys); if (nkeys == 0) { vshError(ctl, _("File %s contains no keys"), from); - goto cleanup; + return false; } } if (virDomainAuthorizedSSHKeysSet(dom, user, (const char **) keys, nkeys, flags) < 0) { - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } @@ -14200,23 +14018,19 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int seconds = 1; /* the default value is 1 */ - bool ret = false; if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0) - goto cleanup; + return false; if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) - goto cleanup; + return false; vshPrintExtra(ctl, _("Start to calculate domain's memory " "dirty rate successfully.\n")); - ret = true; - - cleanup: - return ret; + return true; } diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a32af023ae..2b8b953648 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -97,7 +97,6 @@ static const vshCmdOptDef opts_domcapabilities[] = { static bool cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; g_autofree char *caps = NULL; const char *virttype = NULL; const char *emulatorbin = NULL; @@ -110,19 +109,17 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 || vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) - return ret; + return false; caps = virConnectGetDomainCapabilities(priv->conn, emulatorbin, arch, machine, virttype, flags); if (!caps) { vshError(ctl, "%s", _("failed to get emulator capabilities")); - goto cleanup; + return false; } vshPrint(ctl, "%s\n", caps); - ret = true; - cleanup: - return ret; + return true; } /* @@ -154,7 +151,6 @@ static const vshCmdOptDef opts_freecell[] = { static bool cmdFreecell(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; int cell = -1; unsigned long long memory = 0; g_autofree xmlNodePtr *nodes = NULL; @@ -177,13 +173,13 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (all) { if (!(cap_xml = virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell", @@ -192,7 +188,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt == -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } nodes_free = g_new0(unsigned long long, nodes_cnt); @@ -203,14 +199,14 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - goto cleanup; + return false; } nodes_id[i] = id; if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]), id, 1) != 1) { vshError(ctl, _("failed to get free memory for NUMA node " "number: %lu"), id); - goto cleanup; + return false; } } @@ -225,21 +221,18 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) } else { if (cellno) { if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != 1) - goto cleanup; + return false; vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); } else { if ((memory = virNodeGetFreeMemory(priv->conn)) == 0) - goto cleanup; + return false; vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); } } - ret = true; - - cleanup: - return ret; + return true; } @@ -476,7 +469,6 @@ static const vshCmdOptDef opts_allocpages[] = { static bool cmdAllocpages(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; bool add = vshCommandOptBool(cmd, "add"); bool all = vshCommandOptBool(cmd, "all"); bool cellno = vshCommandOptBool(cmd, "cellno"); @@ -511,13 +503,13 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (!(cap_xml = virConnectGetCapabilities(priv->conn))) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt); if (!xml) { vshError(ctl, "%s", _("unable to get node capabilities")); - goto cleanup; + return false; } nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell", @@ -526,7 +518,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) if (nodes_cnt == -1) { vshError(ctl, "%s", _("could not get information about " "NUMA topology")); - goto cleanup; + return false; } for (i = 0; i < nodes_cnt; i++) { @@ -534,22 +526,20 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) g_autofree char *val = virXMLPropString(nodes[i], "id"); if (virStrToLong_ulp(val, NULL, 10, &id)) { vshError(ctl, "%s", _("conversion from string failed")); - goto cleanup; + return false; } if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts, id, 1, flags) < 0) - goto cleanup; + return false; } } else { if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts, startCell, cellCount, flags) < 0) - goto cleanup; + return false; } - ret = true; - cleanup: - return ret; + return true; } @@ -583,7 +573,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlXPathContext) ctxt = NULL; virshControl *priv = ctl->privData; - bool ret = false; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) return false; @@ -591,7 +580,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) if ((caps = virConnectGetDomainCapabilities(priv->conn, NULL, NULL, NULL, type, 0))) { if (!(xml = virXMLParseStringCtxt(caps, _("(domainCapabilities)"), &ctxt))) - goto cleanup; + return false; ignore_value(virXPathInt("string(./vcpu[1]/@max)", ctxt, &vcpus)); } else { @@ -599,13 +588,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) } if (vcpus < 0 && (vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0) - goto cleanup; + return false; vshPrint(ctl, "%d\n", vcpus); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -673,13 +659,12 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) g_autofree unsigned char *cpumap = NULL; unsigned int online; bool pretty = vshCommandOptBool(cmd, "pretty"); - bool ret = false; virshControl *priv = ctl->privData; cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0); if (cpunum < 0) { vshError(ctl, "%s", _("Unable to get cpu map")); - goto cleanup; + return false; } vshPrint(ctl, "%-15s %d\n", _("CPUs present:"), cpunum); @@ -690,7 +675,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) g_autofree char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum)); if (!str) - goto cleanup; + return false; vshPrint(ctl, "%s", str); } else { for (cpu = 0; cpu < cpunum; cpu++) @@ -698,10 +683,7 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) } vshPrint(ctl, "\n"); - ret = true; - - cleanup: - return ret; + return true; } /* @@ -767,7 +749,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; g_autofree virNodeCPUStatsPtr params = NULL; int nparams = 0; - bool ret = false; unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 }; bool present[VIRSH_CPU_LAST] = { false }; virshControl *priv = ctl->privData; @@ -791,7 +772,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) for (i = 0; i < 2; i++) { if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get node cpu stats")); - goto cleanup; + return false; } for (j = 0; j < nparams; j++) { @@ -845,10 +826,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) } } - ret = true; - - cleanup: - return ret; + return true; } /* @@ -879,7 +857,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) size_t i; int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; g_autofree virNodeMemoryStatsPtr params = NULL; - bool ret = false; virshControl *priv = ctl->privData; if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) @@ -889,29 +866,25 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) if (virNodeGetMemoryStats(priv->conn, cellNum, NULL, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get number of memory stats")); - goto cleanup; + return false; } if (nparams == 0) { /* nothing to output */ - ret = true; - goto cleanup; + return true; } /* now go get all the memory parameters */ params = g_new0(virNodeMemoryStats, nparams); if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, 0) != 0) { vshError(ctl, "%s", _("Unable to get memory stats")); - goto cleanup; + return false; } for (i = 0; i < nparams; i++) vshPrint(ctl, "%-7s: %20llu KiB\n", params[i].field, params[i].value); - ret = true; - - cleanup: - return ret; + return true; } /* diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c4b1d556ca..945ccc7f45 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -122,11 +122,11 @@ vshFindNodeDevice(vshControl *ctl, const char *value) narr = vshStringToArray(value, &arr); if (narr != 2) { vshError(ctl, _("Malformed device value '%s'"), value); - goto cleanup; + return NULL; } if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1])) - goto cleanup; + return NULL; dev = virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1], 0); } else { @@ -135,10 +135,9 @@ vshFindNodeDevice(vshControl *ctl, const char *value) if (!dev) { vshError(ctl, "%s '%s'", _("Could not find matching device"), value); - goto cleanup; + return NULL; } - cleanup: return dev; } diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b4dfcc2f7a..c51dc023e3 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -529,17 +529,16 @@ virshMakeCloneXML(const char *origxml, const char *newname) doc = virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt); if (!doc) - goto cleanup; + return NULL; obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt); if (obj == NULL || obj->nodesetval == NULL || obj->nodesetval->nodeTab == NULL) - goto cleanup; + return NULL; xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newname); xmlDocDumpMemory(doc, &newxml, &size); - cleanup: return newxml; } diff --git a/tools/vsh.c b/tools/vsh.c index f9600bafba..4356bc391d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -432,7 +432,6 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, bool report) { size_t i; - const vshCmdOptDef *ret = NULL; g_autofree char *alias = NULL; if (STREQ(name, helpopt.name)) @@ -457,7 +456,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, if (report) vshError(ctl, _("invalid '=' after option --%s"), opt->name); - goto cleanup; + return NULL; } *optstr = g_strdup(value + 1); } @@ -466,12 +465,11 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, if ((*opts_seen & (1ULL << i)) && opt->type != VSH_OT_ARGV) { if (report) vshError(ctl, _("option --%s already seen"), name); - goto cleanup; + return NULL; } *opts_seen |= 1ULL << i; *opt_index = i; - ret = opt; - goto cleanup; + return opt; } } @@ -479,8 +477,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, vshError(ctl, _("command '%s' doesn't support option --%s"), cmd->name, name); } - cleanup: - return ret; + return NULL; } static const vshCmdOptDef * -- 2.31.1

On Thu, Aug 12, 2021 at 10:32:50AM +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-completer-domain.c | 30 +- tools/virsh-domain-monitor.c | 128 +++---- tools/virsh-domain.c | 634 ++++++++++++--------------------- tools/virsh-host.c | 87 ++--- tools/virsh-nodedev.c | 7 +- tools/virsh-volume.c | 5 +- tools/vsh.c | 11 +- 7 files changed, 317 insertions(+), 585 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0b536b75dd..d06c24cc74 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1066,13 +1060,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { vshError(ctl, "%s", _("Failed to attach interface")); - } else { - vshPrintExtra(ctl, "%s", _("Interface attached successfully\n")); - functionReturn = true; + return false; }
- cleanup: - return functionReturn; + vshPrintExtra(ctl, "%s", _("Interface attached successfully\n"));
It'd be nice if there was an empty line in here (before the return) O:-)
+ return true; }
/* @@ -3150,29 +3136,25 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) BAD_CAST "link", NULL); if (!cur) - goto cleanup; + return false;
if (xmlNewProp(cur, BAD_CAST "state", BAD_CAST state) == NULL) - goto cleanup; + return false; }
if (!(xml_buf = virXMLNodeToString(xml, obj->nodesetval->nodeTab[i]))) { vshSaveLibvirtError(); vshError(ctl, _("Failed to create XML")); - goto cleanup; + return false; }
if (virDomainUpdateDeviceFlags(dom, xml_buf, flags) < 0) { vshError(ctl, _("Failed to update interface link state")); - goto cleanup; - } else { - vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); - ret = true; + return false; }
- cleanup: - - return ret; + vshPrintExtra(ctl, "%s", _("Device updated successfully\n"));
same here
+ return true; }
/* "domiftune" command @@ -5460,18 +5406,18 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) true, doDump, &data) < 0) - goto cleanup; + return false;
virshWatchJob(ctl, dom, verbose, eventLoop, &data.ret, 0, NULL, NULL, _("Dump"));
virThreadJoin(&workerThread);
- if (!data.ret) - vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to); + if (data.ret) + return false;
- cleanup: - return !data.ret; + vshPrintExtra(ctl, _("\nDomain '%s' dumped to %s\n"), name, to);
and here
+ return true; }
static const vshCmdInfo info_screenshot[] = { @@ -7089,25 +7013,22 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) /* Query mode: show CPU affinity information then exit.*/ if (!cpulist) { ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags); - goto cleanup; + return false; }
/* Pin mode: pinning specified vcpu to specified physical cpus */ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu))) - goto cleanup; + return false;
/* use old API without any explicit flags */ if (flags == VIR_DOMAIN_AFFECT_CURRENT && !current) { if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0) - goto cleanup; + return false; } else { if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0) - goto cleanup; + return false; } - ret = true; -
also the empty line could have stayed here =(
- cleanup: - return ret; + return true; }
/* @@ -10136,7 +10015,6 @@ static const vshCmdOptDef opts_domxmltonative[] = { static bool cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) { - bool ret = false; const char *format = NULL; const char *xmlFile = NULL; g_autofree char *configData = NULL; @@ -10159,26 +10037,22 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) xmlData = virDomainGetXMLDesc(dom, flags); } else if (xmlFile) { if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0) - goto cleanup; + return false; } else { vshError(ctl, "%s", _("need either domain or domain XML")); - goto cleanup; + return false; }
if (!xmlData) { vshError(ctl, "%s", _("failed to retrieve XML")); - goto cleanup; + return false; }
- if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) { - goto cleanup; - } else { - vshPrint(ctl, "%s", configData); - ret = true; - } + if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) + return false;
- cleanup: - return ret; + vshPrint(ctl, "%s", configData);
è qui
+ return true; }
/* @@ -10246,22 +10120,18 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *new_name = NULL; - bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) - return ret; + return false;
if (vshCommandOptStringReq(ctl, cmd, "new-name", &new_name) < 0) - goto cleanup; + return false;
if (virDomainRename(dom, new_name, 0) < 0) - goto cleanup; + return false;
vshPrintExtra(ctl, "Domain successfully renamed\n"); - ret = true; -
y aquí
- cleanup: - return ret; + return true; }
/* @@ -11948,14 +11786,11 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
if (virDomainUpdateDeviceFlags(dom, buffer, flags) < 0) { vshError(ctl, _("Failed to update device from %s"), from); - goto cleanup; + return false; }
vshPrintExtra(ctl, "%s", _("Device updated successfully\n")); - ret = true; -
e aqui
- cleanup: - return ret; + return true; }
/* @@ -12245,9 +12079,7 @@ virshFindDisk(const char *doc, }
vshError(NULL, _("No disk found whose source path or target is %s"), path); -
you know the drill
- cleanup: - return ret; + return NULL; }
typedef enum { @@ -14200,23 +14018,19 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; int seconds = 1; /* the default value is 1 */ - bool ret = false;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false;
if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0) - goto cleanup; + return false;
if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) - goto cleanup; + return false;
vshPrintExtra(ctl, _("Start to calculate domain's memory " "dirty rate successfully.\n")); - ret = true; -
conosci il trapano
- cleanup: - return ret; + return true; }
diff --git a/tools/virsh-host.c b/tools/virsh-host.c index a32af023ae..2b8b953648 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -110,19 +109,17 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 || vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 || vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) - return ret; + return false;
caps = virConnectGetDomainCapabilities(priv->conn, emulatorbin, arch, machine, virttype, flags); if (!caps) { vshError(ctl, "%s", _("failed to get emulator capabilities")); - goto cleanup; + return false; }
vshPrint(ctl, "%s\n", caps);
...
- ret = true; - cleanup: - return ret; + return true; }
/* @@ -599,13 +588,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) }
if (vcpus < 0 && (vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0) - goto cleanup; + return false;
vshPrint(ctl, "%d\n", vcpus);
...
- ret = true; - - cleanup: - return ret; + return true; }
/*

fixup /ˈfɪksʌp/ n. the next best thing after getting it right the first time Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d06c24cc74..e985090992 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6970,7 +6970,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom = NULL; unsigned int vcpu = 0; const char *cpulist = NULL; - bool ret = false; g_autofree unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; @@ -7012,8 +7011,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) /* Query mode: show CPU affinity information then exit.*/ if (!cpulist) { - ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags); - return false; + return virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags); } /* Pin mode: pinning specified vcpu to specified physical cpus */ @@ -7063,7 +7061,6 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom = NULL; const char *cpulist = NULL; - bool ret = false; g_autofree unsigned char *cpumap = NULL; int cpumaplen; int maxcpu; @@ -7099,6 +7096,8 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) /* Query mode: show CPU affinity information then exit.*/ if (query) { + bool ret = false; + /* When query mode and neither "live", "config" nor "current" * is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */ if (flags == -1) @@ -7114,7 +7113,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = virshPrintPinInfo(ctl, cpumap, cpumaplen); vshPrint(ctl, "\n"); } - return false; + return ret; } /* Pin mode: pinning emulator threads to specified physical cpus */ -- 2.31.1

On Thu, Aug 12, 2021 at 10:32:38AM +0200, Ján Tomko wrote:
Incomprehensive series removing many cleanup sections.
Patch 1/12 is common with my other series: [libvirt PATCH 0/3] xml: use g_auto for xmlXPathObject
Ján Tomko (12): util: define cleanup func for xmlXPathObject tools: virsh: split variable declarations tools: virsh: cmdDominfo: rename 'ostype' variable tools: virsh: use automatic cleanup for virDomainObj tools: virsh: use automatic cleanup for xmlXPathContext tools: virsh: use automatic cleanup for xmlXPathObject tools: virsh: use automatic cleanup for xmlDoc tools: virsh: use automatic cleanup for vshTable tools: virsh: reduce variable scope to use automatic cleanup tools: virsh: use automatic cleanup for char ** tools: virsh: use g_autofree tools: virsh: remove redundant labels
with the 13/12 fixup for 12/12 Reviewed-by: Martin Kletzander <mkletzan@redhat.com> The empty lines (see PATCH 12/12) are something I feel would make it consistent with the rest of the code, but feel free to disagree.
participants (2)
-
Ján Tomko
-
Martin Kletzander