Signed-off-by: Ján Tomko <jtomko(a)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