1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-09-20 05:44:53 +03:00

tools: virsh: use g_autofree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Ján Tomko
2021-08-11 15:25:15 +02:00
parent 07b40abe0f
commit fba265e2b2
12 changed files with 122 additions and 257 deletions

View File

@@ -583,7 +583,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlDoc) xmldoc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
int ndisks; int ndisks;
xmlNodePtr *disks = NULL; g_autofree xmlNodePtr *disks = NULL;
size_t i; size_t i;
bool details = false; bool details = false;
g_autoptr(vshTable) table = NULL; g_autoptr(vshTable) table = NULL;
@@ -670,7 +670,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(disks);
return ret; return ret;
} }
@@ -700,7 +699,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
g_autoptr(xmlDoc) xmldoc = NULL; g_autoptr(xmlDoc) xmldoc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
int ninterfaces; int ninterfaces;
xmlNodePtr *interfaces = NULL; g_autofree xmlNodePtr *interfaces = NULL;
size_t i; size_t i;
g_autoptr(vshTable) table = NULL; g_autoptr(vshTable) table = NULL;
@@ -754,7 +753,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(interfaces);
return ret; return ret;
} }
@@ -791,13 +789,13 @@ static bool
cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
{ {
const char *iface = NULL; const char *iface = NULL;
char *state = NULL; g_autofree char *state = NULL;
char *xpath = NULL; g_autofree char *xpath = NULL;
virMacAddr macaddr; virMacAddr macaddr;
char macstr[VIR_MAC_STRING_BUFLEN] = ""; char macstr[VIR_MAC_STRING_BUFLEN] = "";
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *interfaces = NULL; g_autofree xmlNodePtr *interfaces = NULL;
int ninterfaces; int ninterfaces;
unsigned int flags = 0; unsigned int flags = 0;
bool ret = false; bool ret = false;
@@ -846,9 +844,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(state);
VIR_FREE(interfaces);
VIR_FREE(xpath);
return ret; return ret;
} }
@@ -977,7 +972,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *name = NULL, *device = NULL; const char *name = NULL, *device = NULL;
virDomainBlockStatsStruct stats; virDomainBlockStatsStruct stats;
virTypedParameterPtr params = NULL; g_autofree virTypedParameterPtr params = NULL;
virTypedParameterPtr par = NULL; virTypedParameterPtr par = NULL;
const char *field = NULL; const char *field = NULL;
int rc, nparams = 0; int rc, nparams = 0;
@@ -1085,7 +1080,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(params);
return ret; return ret;
} }
#undef DOMBLKSTAT_LEGACY_PRINT #undef DOMBLKSTAT_LEGACY_PRINT

View File

@@ -890,7 +890,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
int ret; int ret;
bool functionReturn = false; bool functionReturn = false;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *xml = NULL; g_autofree char *xml = NULL;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
@@ -1072,7 +1072,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
VIR_FREE(xml);
return functionReturn; return functionReturn;
} }
@@ -1424,9 +1423,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
} }
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str); vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} else { } else {
if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0) if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0)
@@ -1619,9 +1617,8 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
} }
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str); vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} else { } else {
/* set the blkio parameters */ /* set the blkio parameters */
@@ -3067,7 +3064,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathObject) obj = NULL;
xmlNodePtr cur = NULL; xmlNodePtr cur = NULL;
char *xml_buf = NULL; g_autofree char *xml_buf = NULL;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
@@ -3174,7 +3171,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
VIR_FREE(xml_buf);
return ret; return ret;
} }
@@ -3352,9 +3348,8 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
} }
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str); vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} else { } else {
if (virDomainSetInterfaceParameters(dom, device, params, if (virDomainSetInterfaceParameters(dom, device, params,
@@ -4048,7 +4043,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = VIR_DOMAIN_NONE; unsigned int flags = VIR_DOMAIN_NONE;
int rc; int rc;
size_t nfds = 0; size_t nfds = 0;
int *fds = NULL; g_autofree int *fds = NULL;
if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL, if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
VIRSH_BYNAME | VIRSH_BYUUID))) VIRSH_BYNAME | VIRSH_BYUUID)))
@@ -4115,7 +4110,6 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(fds);
return ret; return ret;
} }
@@ -4169,7 +4163,7 @@ doSave(void *opaque)
const char *to = NULL; const char *to = NULL;
unsigned int flags = 0; unsigned int flags = 0;
const char *xmlfile = NULL; const char *xmlfile = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
#ifndef WIN32 #ifndef WIN32
sigset_t sigmask, oldsigmask; sigset_t sigmask, oldsigmask;
@@ -4215,7 +4209,6 @@ doSave(void *opaque)
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig: out_sig:
#endif /* !WIN32 */ #endif /* !WIN32 */
VIR_FREE(xml);
g_main_loop_quit(data->eventLoop); g_main_loop_quit(data->eventLoop);
} }
@@ -4494,7 +4487,7 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd)
const char *file = NULL; const char *file = NULL;
bool ret = false; bool ret = false;
unsigned int flags = 0; unsigned int flags = 0;
char *xml = NULL; g_autofree char *xml = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptBool(cmd, "security-info")) if (vshCommandOptBool(cmd, "security-info"))
@@ -4511,7 +4504,6 @@ cmdSaveImageDumpxml(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
return ret; return ret;
} }
@@ -4552,7 +4544,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd)
const char *file = NULL; const char *file = NULL;
bool ret = false; bool ret = false;
const char *xmlfile = NULL; const char *xmlfile = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
unsigned int flags = 0; unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -4579,7 +4571,6 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
return ret; return ret;
} }
@@ -4918,7 +4909,7 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
unsigned int flags = 0; unsigned int flags = 0;
char *xml = NULL; g_autofree char *xml = NULL;
if (vshCommandOptBool(cmd, "security-info")) if (vshCommandOptBool(cmd, "security-info"))
flags |= VIR_DOMAIN_XML_SECURE; flags |= VIR_DOMAIN_XML_SECURE;
@@ -4933,7 +4924,6 @@ cmdManagedSaveDumpxml(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
return ret; return ret;
} }
@@ -4974,7 +4964,7 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *xmlfile = NULL; const char *xmlfile = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
unsigned int flags = 0; unsigned int flags = 0;
if (vshCommandOptBool(cmd, "running")) if (vshCommandOptBool(cmd, "running"))
@@ -5004,7 +4994,6 @@ cmdManagedSaveDefine(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
return ret; return ret;
} }
@@ -5278,7 +5267,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
unsigned int flags = 0; unsigned int flags = 0;
const char *xmlfile = NULL; const char *xmlfile = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -5309,7 +5298,6 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
return ret; return ret;
} }
@@ -6702,7 +6690,7 @@ virshVcpuinfoPrintAffinity(vshControl *ctl,
int maxcpu, int maxcpu,
bool pretty) bool pretty)
{ {
char *str = NULL; g_autofree char *str = NULL;
size_t i; size_t i;
int ret = -1; int ret = -1;
@@ -6720,7 +6708,6 @@ virshVcpuinfoPrintAffinity(vshControl *ctl,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(str);
return ret; return ret;
} }
@@ -6734,7 +6721,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
virBitmap *ret = NULL; virBitmap *ret = NULL;
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
int nnodes; int nnodes;
size_t i; size_t i;
unsigned int curvcpus = 0; unsigned int curvcpus = 0;
@@ -6787,7 +6774,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
} }
cleanup: cleanup:
VIR_FREE(nodes);
return ret; return ret;
} }
@@ -6937,13 +6923,12 @@ virshPrintPinInfo(vshControl *ctl,
unsigned char *cpumap, unsigned char *cpumap,
size_t cpumaplen) size_t cpumaplen)
{ {
char *str = NULL; g_autofree char *str = NULL;
if (!(str = virBitmapDataFormat(cpumap, cpumaplen))) if (!(str = virBitmapDataFormat(cpumap, cpumaplen)))
return false; return false;
vshPrint(ctl, "%s", str); vshPrint(ctl, "%s", str);
VIR_FREE(str);
return true; return true;
} }
@@ -6956,7 +6941,7 @@ virshVcpuPinQuery(vshControl *ctl,
int maxcpu, int maxcpu,
unsigned int flags) unsigned int flags)
{ {
unsigned char *cpumap = NULL; g_autofree unsigned char *cpumap = NULL;
unsigned int countFlags = flags | VIR_DOMAIN_VCPU_MAXIMUM; unsigned int countFlags = flags | VIR_DOMAIN_VCPU_MAXIMUM;
int cpumaplen; int cpumaplen;
size_t i; size_t i;
@@ -7017,7 +7002,6 @@ virshVcpuPinQuery(vshControl *ctl,
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cpumap);
return ret; return ret;
} }
@@ -7063,7 +7047,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
unsigned int vcpu = 0; unsigned int vcpu = 0;
const char *cpulist = NULL; const char *cpulist = NULL;
bool ret = false; bool ret = false;
unsigned char *cpumap = NULL; g_autofree unsigned char *cpumap = NULL;
int cpumaplen; int cpumaplen;
int maxcpu; int maxcpu;
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
@@ -7123,7 +7107,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cpumap);
return ret; return ret;
} }
@@ -7160,7 +7143,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *cpulist = NULL; const char *cpulist = NULL;
bool ret = false; bool ret = false;
unsigned char *cpumap = NULL; g_autofree unsigned char *cpumap = NULL;
int cpumaplen; int cpumaplen;
int maxcpu; int maxcpu;
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
@@ -7225,7 +7208,6 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cpumap);
return ret; return ret;
} }
@@ -7680,7 +7662,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
unsigned int iothread_id = 0; unsigned int iothread_id = 0;
int maxcpu; int maxcpu;
bool ret = false; bool ret = false;
unsigned char *cpumap = NULL; g_autofree unsigned char *cpumap = NULL;
int cpumaplen; int cpumaplen;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -7715,7 +7697,6 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cpumap);
return ret; return ret;
} }
@@ -7996,9 +7977,8 @@ vshCPUStatsPrintField(vshControl *ctl,
param->value.ul / 1000000000, param->value.ul / 1000000000,
param->value.ul % 1000000000); param->value.ul % 1000000000);
} else { } else {
char *s = vshGetTypedParamValue(ctl, param); g_autofree char *s = vshGetTypedParamValue(ctl, param);
vshPrint(ctl, "%s\n", s); vshPrint(ctl, "%s\n", s);
VIR_FREE(s);
} }
} }
@@ -8180,13 +8160,13 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = false; bool ret = false;
char *buffer; g_autofree char *buffer = NULL;
#ifndef WIN32 #ifndef WIN32
bool console = vshCommandOptBool(cmd, "console"); bool console = vshCommandOptBool(cmd, "console");
#endif #endif
unsigned int flags = 0; unsigned int flags = 0;
size_t nfds = 0; size_t nfds = 0;
int *fds = NULL; g_autofree int *fds = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -8224,8 +8204,6 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(buffer);
VIR_FREE(fds);
return ret; return ret;
} }
@@ -8623,14 +8601,13 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, "%s\n", _("Metadata modified")); vshPrintExtra(ctl, "%s\n", _("Metadata modified"));
} else { } else {
char *data; g_autofree char *data = NULL;
/* get */ /* get */
if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, if (!(data = virDomainGetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT,
uri, flags))) uri, flags)))
goto cleanup; goto cleanup;
vshPrint(ctl, "%s\n", data); vshPrint(ctl, "%s\n", data);
VIR_FREE(data);
} }
ret = true; ret = true;
@@ -9172,9 +9149,8 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd)
params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) { params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) {
vshPrint(ctl, "%-15s: %s\n", params[i].field, _("unlimited")); vshPrint(ctl, "%-15s: %s\n", params[i].field, _("unlimited"));
} else { } else {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str); vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} }
} else { } else {
@@ -9441,9 +9417,8 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd)
vshPrint(ctl, "%-15s: %s\n", params[i].field, vshPrint(ctl, "%-15s: %s\n", params[i].field,
virDomainNumatuneMemModeTypeToString(params[i].value.i)); virDomainNumatuneMemModeTypeToString(params[i].value.i));
} else { } else {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str); vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} }
} else { } else {
@@ -9587,7 +9562,7 @@ virshEventQemuPrint(virConnectPtr conn G_GNUC_UNUSED,
{ {
virshQemuEventData *data = opaque; virshQemuEventData *data = opaque;
virJSONValue *pretty = NULL; virJSONValue *pretty = NULL;
char *str = NULL; g_autofree char *str = NULL;
if (!data->loop && data->count) if (!data->loop && data->count)
return; return;
@@ -9613,8 +9588,6 @@ virshEventQemuPrint(virConnectPtr conn G_GNUC_UNUSED,
data->count++; data->count++;
if (!data->loop) if (!data->loop)
vshEventDone(data->ctl); vshEventDone(data->ctl);
VIR_FREE(str);
} }
static const vshCmdInfo info_qemu_monitor_event[] = { static const vshCmdInfo info_qemu_monitor_event[] = {
@@ -9917,15 +9890,15 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
bool ret = false; bool ret = false;
const vshCmdOpt *opt = NULL; const vshCmdOpt *opt = NULL;
char **cmdargv = NULL; g_autofree char **cmdargv = NULL;
size_t ncmdargv = 0; size_t ncmdargv = 0;
pid_t pid; pid_t pid;
int nfdlist; int nfdlist;
int *fdlist; int *fdlist;
size_t i; size_t i;
bool setlabel = true; bool setlabel = true;
virSecurityModelPtr secmodel = NULL; g_autofree virSecurityModelPtr secmodel = NULL;
virSecurityLabelPtr seclabel = NULL; g_autofree virSecurityLabelPtr seclabel = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
dom = virshCommandOptDomain(ctl, cmd, NULL); dom = virshCommandOptDomain(ctl, cmd, NULL);
@@ -10007,9 +9980,6 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(seclabel);
VIR_FREE(secmodel);
VIR_FREE(cmdargv);
return ret; return ret;
} }
@@ -10052,7 +10022,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
unsigned int flags = 0; unsigned int flags = 0;
bool inactive = vshCommandOptBool(cmd, "inactive"); bool inactive = vshCommandOptBool(cmd, "inactive");
bool secure = vshCommandOptBool(cmd, "security-info"); bool secure = vshCommandOptBool(cmd, "security-info");
@@ -10074,7 +10044,6 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virDomainGetXMLDesc(dom, flags); dump = virDomainGetXMLDesc(dom, flags);
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }
@@ -10115,8 +10084,8 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *format = NULL; const char *format = NULL;
const char *configFile = NULL; const char *configFile = NULL;
char *configData; g_autofree char *configData = NULL;
char *xmlData; g_autofree char *xmlData = NULL;
unsigned int flags = 0; unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -10130,12 +10099,10 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
xmlData = virConnectDomainXMLFromNative(priv->conn, format, configData, flags); xmlData = virConnectDomainXMLFromNative(priv->conn, format, configData, flags);
if (xmlData != NULL) { if (xmlData != NULL) {
vshPrint(ctl, "%s", xmlData); vshPrint(ctl, "%s", xmlData);
VIR_FREE(xmlData);
} else { } else {
ret = false; ret = false;
} }
VIR_FREE(configData);
return ret; return ret;
} }
@@ -10172,8 +10139,8 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
const char *format = NULL; const char *format = NULL;
const char *xmlFile = NULL; const char *xmlFile = NULL;
char *configData = NULL; g_autofree char *configData = NULL;
char *xmlData = NULL; g_autofree char *xmlData = NULL;
unsigned int flags = 0; unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
@@ -10211,8 +10178,6 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
VIR_FREE(xmlData);
VIR_FREE(configData);
return ret; return ret;
} }
@@ -11615,7 +11580,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
bool ret = false; bool ret = false;
int port = 0; int port = 0;
char *listen_addr = NULL; g_autofree char *listen_addr = NULL;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
@@ -11658,7 +11623,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(listen_addr);
return ret; return ret;
} }
@@ -11686,7 +11650,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
bool ret = false; bool ret = false;
char *tty = NULL; g_autofree char *tty = NULL;
if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0) if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0)
return false; return false;
@@ -11698,7 +11662,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(tty);
return ret; return ret;
} }
@@ -11947,7 +11910,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *from = NULL; const char *from = NULL;
char *buffer = NULL; g_autofree char *buffer = NULL;
bool ret = false; bool ret = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
@@ -11992,7 +11955,6 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(buffer);
return ret; return ret;
} }
@@ -12042,7 +12004,7 @@ virshDomainDetachInterface(char *doc,
g_autoptr(xmlXPathObject) obj = NULL; g_autoptr(xmlXPathObject) obj = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr cur = NULL, matchNode = NULL; xmlNodePtr cur = NULL, matchNode = NULL;
char *detach_xml = NULL; g_autofree char *detach_xml = NULL;
char buf[64]; char buf[64];
int diff_mac, ret = -1; int diff_mac, ret = -1;
size_t i; size_t i;
@@ -12077,9 +12039,8 @@ virshDomainDetachInterface(char *doc,
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE && if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "mac")) { virXMLNodeNameEqual(cur, "mac")) {
char *tmp_mac = virXMLPropString(cur, "address"); g_autofree char *tmp_mac = virXMLPropString(cur, "address");
diff_mac = virMacAddrCompare(tmp_mac, mac); diff_mac = virMacAddrCompare(tmp_mac, mac);
VIR_FREE(tmp_mac);
if (!diff_mac) { if (!diff_mac) {
if (matchNode) { if (matchNode) {
/* this is the 2nd match, so it's ambiguous */ /* this is the 2nd match, so it's ambiguous */
@@ -12112,7 +12073,6 @@ virshDomainDetachInterface(char *doc,
ret = virDomainDetachDevice(dom, detach_xml); ret = virDomainDetachDevice(dom, detach_xml);
cleanup: cleanup:
VIR_FREE(detach_xml);
return ret == 0; return ret == 0;
} }
@@ -12121,7 +12081,8 @@ static bool
cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; 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; const char *mac = NULL, *type = NULL;
int flags = 0; int flags = 0;
bool ret = false, affect_config, affect_live; bool ret = false, affect_config, affect_live;
@@ -12176,8 +12137,6 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
} else { } else {
vshPrintExtra(ctl, "%s", _("Interface detached successfully\n")); vshPrintExtra(ctl, "%s", _("Interface detached successfully\n"));
} }
VIR_FREE(doc_live);
VIR_FREE(doc_config);
return ret; return ret;
} }
@@ -12248,13 +12207,11 @@ virshFindDisk(const char *doc,
/* Check if the disk is CDROM or floppy disk */ /* Check if the disk is CDROM or floppy disk */
if (virXMLNodeNameEqual(n, "disk")) { if (virXMLNodeNameEqual(n, "disk")) {
char *device_value = virXMLPropString(n, "device"); g_autofree char *device_value = virXMLPropString(n, "device");
if (STREQ(device_value, "cdrom") || if (STREQ(device_value, "cdrom") ||
STREQ(device_value, "floppy")) STREQ(device_value, "floppy"))
is_supported = true; is_supported = true;
VIR_FREE(device_value);
} }
if (!is_supported) if (!is_supported)
@@ -12264,7 +12221,7 @@ virshFindDisk(const char *doc,
cur = obj->nodesetval->nodeTab[i]->children; cur = obj->nodesetval->nodeTab[i]->children;
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) { if (cur->type == XML_ELEMENT_NODE) {
char *tmp = NULL; g_autofree char *tmp = NULL;
if (virXMLNodeNameEqual(cur, "source")) { if (virXMLNodeNameEqual(cur, "source")) {
if ((tmp = virXMLPropString(cur, "file")) || if ((tmp = virXMLPropString(cur, "file")) ||
@@ -12280,10 +12237,8 @@ virshFindDisk(const char *doc,
ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1); ret = xmlCopyNode(obj->nodesetval->nodeTab[i], 1);
/* drop backing store since they are not needed here */ /* drop backing store since they are not needed here */
virshDiskDropBackingStore(ret); virshDiskDropBackingStore(ret);
VIR_FREE(tmp);
goto cleanup; goto cleanup;
} }
VIR_FREE(tmp);
} }
cur = cur->next; cur = cur->next;
} }
@@ -12317,10 +12272,10 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
xmlNodePtr source = NULL; xmlNodePtr source = NULL;
xmlNodePtr target_node = NULL; xmlNodePtr target_node = NULL;
xmlNodePtr text_node = NULL; xmlNodePtr text_node = NULL;
char *device_type = NULL; g_autofree char *device_type = NULL;
char *ret = NULL; char *ret = NULL;
char *startupPolicy = NULL; g_autofree char *startupPolicy = NULL;
char *source_path = NULL; g_autofree char *source_path = NULL;
if (!disk_node) if (!disk_node)
return NULL; return NULL;
@@ -12436,9 +12391,6 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
} }
cleanup: cleanup:
VIR_FREE(device_type);
VIR_FREE(startupPolicy);
VIR_FREE(source_path);
return ret; return ret;
} }
@@ -12478,10 +12430,10 @@ static const vshCmdOptDef opts_detach_disk[] = {
static bool static bool
cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
{ {
char *disk_xml = NULL; g_autofree char *disk_xml = NULL;
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *target = NULL; const char *target = NULL;
char *doc = NULL; g_autofree char *doc = NULL;
int ret; int ret;
bool functionReturn = false; bool functionReturn = false;
xmlNodePtr disk_node = NULL; xmlNodePtr disk_node = NULL;
@@ -12548,8 +12500,6 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
xmlFreeNode(disk_node); xmlFreeNode(disk_node);
VIR_FREE(disk_xml);
VIR_FREE(doc);
return functionReturn; return functionReturn;
} }
@@ -13225,16 +13175,13 @@ virshEventJobCompletedPrint(virConnectPtr conn G_GNUC_UNUSED,
{ {
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i; size_t i;
char *value;
virBufferAsprintf(&buf, _("event 'job-completed' for domain '%s':\n"), virBufferAsprintf(&buf, _("event 'job-completed' for domain '%s':\n"),
virDomainGetName(dom)); virDomainGetName(dom));
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
value = virTypedParameterToString(&params[i]); g_autofree char *value = virTypedParameterToString(&params[i]);
if (value) { if (value)
virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value);
VIR_FREE(value);
}
} }
virshEventPrint(opaque, &buf); virshEventPrint(opaque, &buf);
} }
@@ -13611,9 +13558,9 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
const char *source = NULL; const char *source = NULL;
const char *path = NULL; const char *path = NULL;
char *doc = NULL; g_autofree char *doc = NULL;
xmlNodePtr disk_node = NULL; xmlNodePtr disk_node = NULL;
char *disk_xml = NULL; g_autofree char *disk_xml = NULL;
bool ret = false; bool ret = false;
virshUpdateDiskXMLType update_type; virshUpdateDiskXMLType update_type;
const char *action = NULL; const char *action = NULL;
@@ -13705,9 +13652,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(doc);
xmlFreeNode(disk_node); xmlFreeNode(disk_node);
VIR_FREE(disk_xml);
return ret; return ret;
} }
@@ -13789,7 +13734,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
int ret = -1; int ret = -1;
const vshCmdOpt *opt = NULL; const vshCmdOpt *opt = NULL;
const char **mountpoints = NULL; g_autofree const char **mountpoints = NULL;
size_t nmountpoints = 0; size_t nmountpoints = 0;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
@@ -13809,7 +13754,6 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), ret); vshPrintExtra(ctl, _("Froze %d filesystem(s)\n"), ret);
cleanup: cleanup:
VIR_FREE(mountpoints);
return ret >= 0; return ret >= 0;
} }
@@ -13838,7 +13782,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
int ret = -1; int ret = -1;
const vshCmdOpt *opt = NULL; const vshCmdOpt *opt = NULL;
const char **mountpoints = NULL; g_autofree const char **mountpoints = NULL;
size_t nmountpoints = 0; size_t nmountpoints = 0;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
@@ -13858,7 +13802,6 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), ret); vshPrintExtra(ctl, _("Thawed %d filesystem(s)\n"), ret);
cleanup: cleanup:
VIR_FREE(mountpoints);
return ret >= 0; return ret >= 0;
} }
@@ -14060,9 +14003,8 @@ cmdGuestInfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-20s: %s\n", params[i].field, str); vshPrint(ctl, "%-20s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
ret = true; ret = true;

View File

@@ -49,7 +49,7 @@ static const vshCmdInfo info_capabilities[] = {
static bool static bool
cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
char *caps; g_autofree char *caps = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if ((caps = virConnectGetCapabilities(priv->conn)) == NULL) { if ((caps = virConnectGetCapabilities(priv->conn)) == NULL) {
@@ -57,7 +57,6 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
return false; return false;
} }
vshPrint(ctl, "%s\n", caps); vshPrint(ctl, "%s\n", caps);
VIR_FREE(caps);
return true; return true;
} }
@@ -99,7 +98,7 @@ static bool
cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
{ {
bool ret = false; bool ret = false;
char *caps = NULL; g_autofree char *caps = NULL;
const char *virttype = NULL; const char *virttype = NULL;
const char *emulatorbin = NULL; const char *emulatorbin = NULL;
const char *arch = NULL; const char *arch = NULL;
@@ -123,7 +122,6 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%s\n", caps); vshPrint(ctl, "%s\n", caps);
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(caps);
return ret; return ret;
} }
@@ -159,14 +157,14 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
int cell = -1; int cell = -1;
unsigned long long memory = 0; unsigned long long memory = 0;
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
unsigned long nodes_cnt; unsigned long nodes_cnt;
unsigned long *nodes_id = NULL; g_autofree unsigned long *nodes_id = NULL;
unsigned long long *nodes_free = NULL; g_autofree unsigned long long *nodes_free = NULL;
bool all = vshCommandOptBool(cmd, "all"); bool all = vshCommandOptBool(cmd, "all");
bool cellno = vshCommandOptBool(cmd, "cellno"); bool cellno = vshCommandOptBool(cmd, "cellno");
size_t i; size_t i;
char *cap_xml = NULL; g_autofree char *cap_xml = NULL;
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -202,13 +200,11 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nodes_cnt; i++) { for (i = 0; i < nodes_cnt; i++) {
unsigned long id; unsigned long id;
char *val = virXMLPropString(nodes[i], "id"); g_autofree char *val = virXMLPropString(nodes[i], "id");
if (virStrToLong_ulp(val, NULL, 10, &id)) { if (virStrToLong_ulp(val, NULL, 10, &id)) {
vshError(ctl, "%s", _("conversion from string failed")); vshError(ctl, "%s", _("conversion from string failed"));
VIR_FREE(val);
goto cleanup; goto cleanup;
} }
VIR_FREE(val);
nodes_id[i] = id; nodes_id[i] = id;
if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]), if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]),
id, 1) != 1) { id, 1) != 1) {
@@ -243,10 +239,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(nodes);
VIR_FREE(nodes_free);
VIR_FREE(nodes_id);
VIR_FREE(cap_xml);
return ret; return ret;
} }
@@ -296,15 +288,15 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
{ {
bool ret = false; bool ret = false;
unsigned int npages; unsigned int npages;
unsigned int *pagesize = NULL; g_autofree unsigned int *pagesize = NULL;
unsigned long long bytes = 0; unsigned long long bytes = 0;
unsigned int kibibytes = 0; unsigned int kibibytes = 0;
int cell; int cell;
unsigned long long *counts = NULL; g_autofree unsigned long long *counts = NULL;
size_t i, j; size_t i, j;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int nodes_cnt; int nodes_cnt;
char *cap_xml = NULL; g_autofree char *cap_xml = NULL;
g_autoptr(xmlDoc) doc = NULL; g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
bool all = vshCommandOptBool(cmd, "all"); bool all = vshCommandOptBool(cmd, "all");
@@ -347,15 +339,12 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
pagesize = g_new0(unsigned int, nodes_cnt); pagesize = g_new0(unsigned int, nodes_cnt);
for (i = 0; i < nodes_cnt; i++) { 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) { if (virStrToLong_uip(val, NULL, 10, &pagesize[i]) < 0) {
vshError(ctl, _("unable to parse page size: %s"), val); vshError(ctl, _("unable to parse page size: %s"), val);
VIR_FREE(val);
goto cleanup; goto cleanup;
} }
VIR_FREE(val);
} }
/* Here, if we've done the trick few lines above, /* 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", nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell",
ctxt, &nodes); ctxt, &nodes);
for (i = 0; i < nodes_cnt; i++) { 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) { if (virStrToLong_i(val, NULL, 10, &cell) < 0) {
vshError(ctl, _("unable to parse numa node id: %s"), val); vshError(ctl, _("unable to parse numa node id: %s"), val);
VIR_FREE(val);
goto cleanup; goto cleanup;
} }
VIR_FREE(val);
if (virNodeGetFreePages(priv->conn, npages, pagesize, if (virNodeGetFreePages(priv->conn, npages, pagesize,
cell, 1, counts, 0) < 0) cell, 1, counts, 0) < 0)
@@ -441,10 +428,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cap_xml);
VIR_FREE(nodes); VIR_FREE(nodes);
VIR_FREE(counts);
VIR_FREE(pagesize);
return ret; return ret;
} }
@@ -501,10 +485,10 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
unsigned int pageSizes[1]; unsigned int pageSizes[1];
unsigned long long pageCounts[1], tmp; unsigned long long pageCounts[1], tmp;
unsigned int flags = 0; unsigned int flags = 0;
char *cap_xml = NULL; g_autofree char *cap_xml = NULL;
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
@@ -547,13 +531,11 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nodes_cnt; i++) { for (i = 0; i < nodes_cnt; i++) {
unsigned long id; unsigned long id;
char *val = virXMLPropString(nodes[i], "id"); g_autofree char *val = virXMLPropString(nodes[i], "id");
if (virStrToLong_ulp(val, NULL, 10, &id)) { if (virStrToLong_ulp(val, NULL, 10, &id)) {
vshError(ctl, "%s", _("conversion from string failed")); vshError(ctl, "%s", _("conversion from string failed"));
VIR_FREE(val);
goto cleanup; goto cleanup;
} }
VIR_FREE(val);
if (virNodeAllocPages(priv->conn, 1, pageSizes, if (virNodeAllocPages(priv->conn, 1, pageSizes,
pageCounts, id, 1, flags) < 0) pageCounts, id, 1, flags) < 0)
@@ -567,8 +549,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(nodes);
VIR_FREE(cap_xml);
return ret; return ret;
} }
@@ -599,7 +579,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
{ {
const char *type = NULL; const char *type = NULL;
int vcpus = -1; int vcpus = -1;
char *caps = NULL; g_autofree char *caps = NULL;
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -625,7 +605,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(caps);
return ret; return ret;
} }
@@ -691,7 +670,7 @@ static bool
cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
int cpu, cpunum; int cpu, cpunum;
unsigned char *cpumap = NULL; g_autofree unsigned char *cpumap = NULL;
unsigned int online; unsigned int online;
bool pretty = vshCommandOptBool(cmd, "pretty"); bool pretty = vshCommandOptBool(cmd, "pretty");
bool ret = false; bool ret = false;
@@ -708,12 +687,11 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
vshPrint(ctl, "%-15s ", _("CPU map:")); vshPrint(ctl, "%-15s ", _("CPU map:"));
if (pretty) { if (pretty) {
char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum)); g_autofree char *str = virBitmapDataFormat(cpumap, VIR_CPU_MAPLEN(cpunum));
if (!str) if (!str)
goto cleanup; goto cleanup;
vshPrint(ctl, "%s", str); vshPrint(ctl, "%s", str);
VIR_FREE(str);
} else { } else {
for (cpu = 0; cpu < cpunum; cpu++) for (cpu = 0; cpu < cpunum; cpu++)
vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-'); vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-');
@@ -723,7 +701,6 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cpumap);
return ret; return ret;
} }
@@ -788,7 +765,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
size_t i, j; size_t i, j;
bool flag_percent = vshCommandOptBool(cmd, "percent"); bool flag_percent = vshCommandOptBool(cmd, "percent");
int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS;
virNodeCPUStatsPtr params; g_autofree virNodeCPUStatsPtr params = NULL;
int nparams = 0; int nparams = 0;
bool ret = false; bool ret = false;
unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 }; unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 };
@@ -871,7 +848,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(params);
return ret; return ret;
} }
@@ -902,7 +878,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
int nparams = 0; int nparams = 0;
size_t i; size_t i;
int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
virNodeMemoryStatsPtr params = NULL; g_autofree virNodeMemoryStatsPtr params = NULL;
bool ret = false; bool ret = false;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -935,7 +911,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(params);
return ret; return ret;
} }
@@ -1023,7 +998,7 @@ static const vshCmdInfo info_sysinfo[] = {
static bool static bool
cmdSysinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdSysinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
char *sysinfo; g_autofree char *sysinfo = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
sysinfo = virConnectGetSysinfo(priv->conn, 0); sysinfo = virConnectGetSysinfo(priv->conn, 0);
@@ -1033,7 +1008,6 @@ cmdSysinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
} }
vshPrint(ctl, "%s", sysinfo); vshPrint(ctl, "%s", sysinfo);
VIR_FREE(sysinfo);
return true; return true;
} }
@@ -1054,7 +1028,7 @@ static const vshCmdInfo info_hostname[] = {
static bool static bool
cmdHostname(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdHostname(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
char *hostname; g_autofree char *hostname = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
hostname = virConnectGetHostname(priv->conn); hostname = virConnectGetHostname(priv->conn);
@@ -1064,7 +1038,6 @@ cmdHostname(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
} }
vshPrint(ctl, "%s\n", hostname); vshPrint(ctl, "%s\n", hostname);
VIR_FREE(hostname);
return true; return true;
} }
@@ -1085,7 +1058,7 @@ static const vshCmdInfo info_uri[] = {
static bool static bool
cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
char *uri; g_autofree char *uri = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
uri = virConnectGetURI(priv->conn); uri = virConnectGetURI(priv->conn);
@@ -1095,7 +1068,6 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
} }
vshPrint(ctl, "%s\n", uri); vshPrint(ctl, "%s\n", uri);
VIR_FREE(uri);
return true; return true;
} }
@@ -1114,11 +1086,11 @@ vshExtractCPUDefXMLs(vshControl *ctl,
const char *xmlFile) const char *xmlFile)
{ {
char **cpus = NULL; char **cpus = NULL;
char *buffer = NULL; g_autofree char *buffer = NULL;
char *xmlStr = NULL; g_autofree char *xmlStr = NULL;
g_autoptr(xmlDoc) xml = NULL; g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
char *doc; char *doc;
size_t i; size_t i;
int n; int n;
@@ -1177,9 +1149,6 @@ vshExtractCPUDefXMLs(vshControl *ctl,
} }
cleanup: cleanup:
VIR_FREE(buffer);
VIR_FREE(xmlStr);
VIR_FREE(nodes);
return cpus; return cpus;
error: error:
@@ -1300,7 +1269,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
{ {
const char *from = NULL; const char *from = NULL;
bool ret = false; bool ret = false;
char *result = NULL; g_autofree char *result = NULL;
g_auto(GStrv) list = NULL; g_auto(GStrv) list = NULL;
unsigned int flags = 0; unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -1325,7 +1294,6 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
} }
VIR_FREE(result);
return ret; return ret;
} }
@@ -1577,9 +1545,8 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
*/ */
vshPrint(ctl, _("Shared memory:\n")); vshPrint(ctl, _("Shared memory:\n"));
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
char *str = vshGetTypedParamValue(ctl, &params[i]); g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "\t%-15s %s\n", params[i].field, str); vshPrint(ctl, "\t%-15s %s\n", params[i].field, str);
VIR_FREE(str);
} }
} else { } else {
if (virNodeSetMemoryParameters(priv->conn, params, nparams, flags) != 0) if (virNodeSetMemoryParameters(priv->conn, params, nparams, flags) != 0)
@@ -1766,7 +1733,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
const char *arch = NULL; const char *arch = NULL;
const char *machine = NULL; const char *machine = NULL;
bool ret = false; bool ret = false;
char *result = NULL; g_autofree char *result = NULL;
char **list = NULL; char **list = NULL;
unsigned int flags = 0; unsigned int flags = 0;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -1797,7 +1764,6 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
ret = true; ret = true;
} }
VIR_FREE(result);
g_strfreev(list); g_strfreev(list);
return ret; return ret;
} }

View File

@@ -486,7 +486,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virInterfacePtr iface; virInterfacePtr iface;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
unsigned int flags = 0; unsigned int flags = 0;
bool inactive = vshCommandOptBool(cmd, "inactive"); bool inactive = vshCommandOptBool(cmd, "inactive");
@@ -499,7 +499,6 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virInterfaceGetXMLDesc(iface, flags); dump = virInterfaceGetXMLDesc(iface, flags);
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }
@@ -533,7 +532,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface; virInterfacePtr iface;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -543,7 +542,6 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
return false; return false;
iface = virInterfaceDefineXML(priv->conn, buffer, 0); iface = virInterfaceDefineXML(priv->conn, buffer, 0);
VIR_FREE(buffer);
if (iface != NULL) { if (iface != NULL) {
vshPrintExtra(ctl, _("Interface %s defined from %s\n"), vshPrintExtra(ctl, _("Interface %s defined from %s\n"),

View File

@@ -206,7 +206,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network; virNetworkPtr network;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -216,7 +216,6 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
return false; return false;
network = virNetworkCreateXML(priv->conn, buffer); network = virNetworkCreateXML(priv->conn, buffer);
VIR_FREE(buffer);
if (network != NULL) { if (network != NULL) {
vshPrintExtra(ctl, _("Network %s created from %s\n"), vshPrintExtra(ctl, _("Network %s created from %s\n"),
@@ -254,7 +253,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network; virNetworkPtr network;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -264,7 +263,6 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
return false; return false;
network = virNetworkDefineXML(priv->conn, buffer); network = virNetworkDefineXML(priv->conn, buffer);
VIR_FREE(buffer);
if (network != NULL) { if (network != NULL) {
vshPrintExtra(ctl, _("Network %s defined from %s\n"), vshPrintExtra(ctl, _("Network %s defined from %s\n"),
@@ -343,7 +341,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virNetworkPtr network; virNetworkPtr network;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
unsigned int flags = 0; unsigned int flags = 0;
int inactive; int inactive;
@@ -358,7 +356,6 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }
@@ -964,7 +961,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
const char *sectionStr = NULL; const char *sectionStr = NULL;
int command, section, parentIndex = -1; int command, section, parentIndex = -1;
const char *xml = NULL; const char *xml = NULL;
char *xmlFromFile = NULL; g_autofree char *xmlFromFile = NULL;
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live"); bool live = vshCommandOptBool(cmd, "live");
unsigned int flags = VIR_NETWORK_UPDATE_AFFECT_CURRENT; unsigned int flags = VIR_NETWORK_UPDATE_AFFECT_CURRENT;
@@ -1059,7 +1056,6 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
vshReportError(ctl); vshReportError(ctl);
virNetworkFree(network); virNetworkFree(network);
VIR_FREE(xmlFromFile);
return ret; return ret;
} }
@@ -1556,7 +1552,7 @@ cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network; virNetworkPtr network;
virNetworkPortPtr port = NULL; virNetworkPortPtr port = NULL;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
unsigned int flags = 0; unsigned int flags = 0;
if (!(network = virshCommandOptNetwork(ctl, cmd, NULL))) if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
@@ -1569,7 +1565,6 @@ cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd)
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }

View File

@@ -58,7 +58,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
virNodeDevicePtr dev = NULL; virNodeDevicePtr dev = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -68,7 +68,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
return false; return false;
dev = virNodeDeviceCreateXML(priv->conn, buffer, 0); dev = virNodeDeviceCreateXML(priv->conn, buffer, 0);
VIR_FREE(buffer);
if (dev != NULL) { if (dev != NULL) {
vshPrintExtra(ctl, _("Node device %s created from %s\n"), 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 */ /* filter the list if the list was acquired by fallback means */
for (i = 0; i < list->ndevices; i++) { for (i = 0; i < list->ndevices; i++) {
char **caps = NULL; g_autofree char **caps = NULL;
int ncaps = 0; int ncaps = 0;
bool match = false; bool match = false;
size_t j, k; size_t j, k;
@@ -310,7 +309,6 @@ virshNodeDeviceListCollect(vshControl *ctl,
if ((ncaps = virNodeDeviceListCaps(device, caps, ncaps)) < 0) { if ((ncaps = virNodeDeviceListCaps(device, caps, ncaps)) < 0) {
vshError(ctl, "%s", _("Failed to get capability names of the device")); vshError(ctl, "%s", _("Failed to get capability names of the device"));
VIR_FREE(caps);
goto cleanup; goto cleanup;
} }
@@ -326,8 +324,6 @@ virshNodeDeviceListCollect(vshControl *ctl,
} }
} }
VIR_FREE(caps);
if (!match) if (!match)
goto remove_entry; goto remove_entry;
@@ -586,7 +582,7 @@ static bool
cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virNodeDevicePtr device = NULL; virNodeDevicePtr device = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
const char *device_value = NULL; const char *device_value = NULL;
bool ret = false; bool ret = false;
@@ -605,7 +601,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(xml);
if (device) if (device)
virNodeDeviceFree(device); virNodeDeviceFree(device);
return ret; return ret;
@@ -1084,7 +1079,7 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
virNodeDevice *dev = NULL; virNodeDevice *dev = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -1094,7 +1089,6 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
return false; return false;
dev = virNodeDeviceDefineXML(priv->conn, buffer, 0); dev = virNodeDeviceDefineXML(priv->conn, buffer, 0);
VIR_FREE(buffer);
if (dev != NULL) { if (dev != NULL) {
vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"), vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"),

View File

@@ -90,7 +90,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
virNWFilterPtr nwfilter; virNWFilterPtr nwfilter;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -100,7 +100,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
return false; return false;
nwfilter = virNWFilterDefineXML(priv->conn, buffer); nwfilter = virNWFilterDefineXML(priv->conn, buffer);
VIR_FREE(buffer);
if (nwfilter != NULL) { if (nwfilter != NULL) {
vshPrintExtra(ctl, _("Network filter %s defined from %s\n"), vshPrintExtra(ctl, _("Network filter %s defined from %s\n"),
@@ -185,7 +184,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virNWFilterPtr nwfilter; virNWFilterPtr nwfilter;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL))) if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL)))
return false; return false;
@@ -193,7 +192,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virNWFilterGetXMLDesc(nwfilter, 0); dump = virNWFilterGetXMLDesc(nwfilter, 0);
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }
@@ -600,7 +598,7 @@ cmdNWFilterBindingDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virNWFilterBindingPtr binding; virNWFilterBindingPtr binding;
bool ret = true; bool ret = true;
char *dump; g_autofree char *dump = NULL;
if (!(binding = virshCommandOptNWFilterBinding(ctl, cmd, NULL))) if (!(binding = virshCommandOptNWFilterBinding(ctl, cmd, NULL)))
return false; return false;
@@ -608,7 +606,6 @@ cmdNWFilterBindingDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virNWFilterBindingGetXMLDesc(binding, 0); dump = virNWFilterBindingGetXMLDesc(binding, 0);
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }

View File

@@ -270,7 +270,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr pool; virStoragePoolPtr pool;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
bool build; bool build;
bool overwrite; bool overwrite;
bool no_overwrite; bool no_overwrite;
@@ -298,7 +298,6 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
return false; return false;
pool = virStoragePoolCreateXML(priv->conn, buffer, flags); pool = virStoragePoolCreateXML(priv->conn, buffer, flags);
VIR_FREE(buffer);
if (pool != NULL) { if (pool != NULL) {
vshPrintExtra(ctl, _("Pool %s created from %s\n"), vshPrintExtra(ctl, _("Pool %s created from %s\n"),
@@ -464,7 +463,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
{ {
virStoragePoolPtr pool; virStoragePoolPtr pool;
const char *name; const char *name;
char *xml; g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml"); bool printXML = vshCommandOptBool(cmd, "print-xml");
bool build; bool build;
bool overwrite; bool overwrite;
@@ -491,10 +490,8 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
if (printXML) { if (printXML) {
vshPrint(ctl, "%s", xml); vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
} else { } else {
pool = virStoragePoolCreateXML(priv->conn, xml, flags); pool = virStoragePoolCreateXML(priv->conn, xml, flags);
VIR_FREE(xml);
if (pool != NULL) { if (pool != NULL) {
vshPrintExtra(ctl, _("Pool %s created\n"), name); vshPrintExtra(ctl, _("Pool %s created\n"), name);
@@ -533,7 +530,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr pool; virStoragePoolPtr pool;
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
@@ -543,7 +540,6 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
return false; return false;
pool = virStoragePoolDefineXML(priv->conn, buffer, 0); pool = virStoragePoolDefineXML(priv->conn, buffer, 0);
VIR_FREE(buffer);
if (pool != NULL) { if (pool != NULL) {
vshPrintExtra(ctl, _("Pool %s defined from %s\n"), vshPrintExtra(ctl, _("Pool %s defined from %s\n"),
@@ -574,7 +570,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
{ {
virStoragePoolPtr pool; virStoragePoolPtr pool;
const char *name; const char *name;
char *xml; g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml"); bool printXML = vshCommandOptBool(cmd, "print-xml");
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -583,10 +579,8 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
if (printXML) { if (printXML) {
vshPrint(ctl, "%s", xml); vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
} else { } else {
pool = virStoragePoolDefineXML(priv->conn, xml, 0); pool = virStoragePoolDefineXML(priv->conn, xml, 0);
VIR_FREE(xml);
if (pool != NULL) { if (pool != NULL) {
vshPrintExtra(ctl, _("Pool %s defined\n"), name); vshPrintExtra(ctl, _("Pool %s defined\n"), name);
@@ -799,7 +793,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
bool inactive = vshCommandOptBool(cmd, "inactive"); bool inactive = vshCommandOptBool(cmd, "inactive");
unsigned int flags = 0; unsigned int flags = 0;
char *dump; g_autofree char *dump = NULL;
if (inactive) if (inactive)
flags |= VIR_STORAGE_XML_INACTIVE; flags |= VIR_STORAGE_XML_INACTIVE;
@@ -810,7 +804,6 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
dump = virStoragePoolGetXMLDesc(pool, flags); dump = virStoragePoolGetXMLDesc(pool, flags);
if (dump != NULL) { if (dump != NULL) {
vshPrint(ctl, "%s", dump); vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
} else { } else {
ret = false; ret = false;
} }
@@ -1442,8 +1435,8 @@ static bool
cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED) cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
{ {
const char *type = NULL, *host = NULL; const char *type = NULL, *host = NULL;
char *srcSpec = NULL; g_autofree char *srcSpec = NULL;
char *srcList; g_autofree char *srcList = NULL;
const char *initiator = NULL; const char *initiator = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
@@ -1479,13 +1472,11 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
} }
srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0); srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0);
VIR_FREE(srcSpec);
if (srcList == NULL) { if (srcList == NULL) {
vshError(ctl, _("Failed to find any %s pool sources"), type); vshError(ctl, _("Failed to find any %s pool sources"), type);
return false; return false;
} }
vshPrint(ctl, "%s", srcList); vshPrint(ctl, "%s", srcList);
VIR_FREE(srcList);
return true; return true;
} }
@@ -1832,7 +1823,7 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr pool = NULL; virStoragePoolPtr pool = NULL;
virStoragePoolPtr pool_edited = NULL; virStoragePoolPtr pool_edited = NULL;
unsigned int flags = VIR_STORAGE_XML_INACTIVE; unsigned int flags = VIR_STORAGE_XML_INACTIVE;
char *tmp_desc = NULL; g_autofree char *tmp_desc = NULL;
virshControl *priv = ctl->privData; virshControl *priv = ctl->privData;
pool = virshCommandOptPool(ctl, cmd, "pool", NULL); pool = virshCommandOptPool(ctl, cmd, "pool", NULL);
@@ -1847,8 +1838,6 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
} else { } else {
goto cleanup; goto cleanup;
} }
} else {
VIR_FREE(tmp_desc);
} }
#define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags) #define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags)

View File

@@ -80,7 +80,7 @@ static bool
cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
{ {
const char *from = NULL; const char *from = NULL;
char *buffer; g_autofree char *buffer = NULL;
virSecretPtr res; virSecretPtr res;
char uuid[VIR_UUID_STRING_BUFLEN]; char uuid[VIR_UUID_STRING_BUFLEN];
bool ret = false; bool ret = false;
@@ -106,7 +106,6 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(buffer);
virshSecretFree(res); virshSecretFree(res);
return ret; return ret;
} }
@@ -139,7 +138,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
{ {
virSecretPtr secret; virSecretPtr secret;
bool ret = false; bool ret = false;
char *xml; g_autofree char *xml = NULL;
secret = virshCommandOptSecret(ctl, cmd, NULL); secret = virshCommandOptSecret(ctl, cmd, NULL);
if (secret == NULL) if (secret == NULL)
@@ -149,7 +148,6 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
if (xml == NULL) if (xml == NULL)
goto cleanup; goto cleanup;
vshPrint(ctl, "%s", xml); vshPrint(ctl, "%s", xml);
VIR_FREE(xml);
ret = true; ret = true;
cleanup: cleanup:

View File

@@ -304,7 +304,7 @@ virshDomainGetXMLFromDom(vshControl *ctl,
xmlDocPtr *xml, xmlDocPtr *xml,
xmlXPathContextPtr *ctxt) xmlXPathContextPtr *ctxt)
{ {
char *desc = NULL; g_autofree char *desc = NULL;
if (!(desc = virDomainGetXMLDesc(dom, flags))) { if (!(desc = virDomainGetXMLDesc(dom, flags))) {
vshError(ctl, _("Failed to get domain description xml")); vshError(ctl, _("Failed to get domain description xml"));
@@ -312,7 +312,6 @@ virshDomainGetXMLFromDom(vshControl *ctl,
} }
*xml = virXMLParseStringCtxt(desc, _("(domain_definition)"), ctxt); *xml = virXMLParseStringCtxt(desc, _("(domain_definition)"), ctxt);
VIR_FREE(desc);
if (!(*xml)) { if (!(*xml)) {
vshError(ctl, _("Failed to parse domain description xml")); vshError(ctl, _("Failed to parse domain description xml"));

View File

@@ -233,7 +233,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
{ {
virStoragePoolPtr pool; virStoragePoolPtr pool;
virStorageVolPtr vol = NULL; virStorageVolPtr vol = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
bool printXML = vshCommandOptBool(cmd, "print-xml"); bool printXML = vshCommandOptBool(cmd, "print-xml");
const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL; const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL;
const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL; const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL;
@@ -290,7 +290,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
/* Convert the snapshot parameters into backingStore XML */ /* Convert the snapshot parameters into backingStore XML */
if (snapshotStrVol) { if (snapshotStrVol) {
virStorageVolPtr snapVol; virStorageVolPtr snapVol;
char *snapshotStrVolPath; g_autofree char *snapshotStrVolPath = NULL;
/* Lookup snapshot backing volume. Try the backing-vol /* Lookup snapshot backing volume. Try the backing-vol
* parameter as a name */ * parameter as a name */
vshDebug(ctl, VSH_ERR_DEBUG, vshDebug(ctl, VSH_ERR_DEBUG,
@@ -347,7 +347,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
virBufferAddLit(&buf, "</backingStore>\n"); virBufferAddLit(&buf, "</backingStore>\n");
/* Cleanup snapshot allocations */ /* Cleanup snapshot allocations */
VIR_FREE(snapshotStrVolPath);
virStorageVolFree(snapVol); virStorageVolFree(snapVol);
} }
@@ -372,7 +371,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
if (vol) if (vol)
virStorageVolFree(vol); virStorageVolFree(vol);
virStoragePoolFree(pool); virStoragePoolFree(pool);
VIR_FREE(xml);
return ret; return ret;
} }
@@ -407,7 +405,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL; const char *from = NULL;
bool ret = false; bool ret = false;
unsigned int flags = 0; unsigned int flags = 0;
char *buffer = NULL; g_autofree char *buffer = NULL;
if (vshCommandOptBool(cmd, "prealloc-metadata")) if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
@@ -433,7 +431,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
} }
cleanup: cleanup:
VIR_FREE(buffer);
virStoragePoolFree(pool); virStoragePoolFree(pool);
return ret; return ret;
} }
@@ -477,7 +474,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr newvol = NULL, inputvol = NULL; virStorageVolPtr newvol = NULL, inputvol = NULL;
const char *from = NULL; const char *from = NULL;
bool ret = false; bool ret = false;
char *buffer = NULL; g_autofree char *buffer = NULL;
unsigned int flags = 0; unsigned int flags = 0;
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL))) if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
@@ -512,7 +509,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(buffer);
if (pool) if (pool)
virStoragePoolFree(pool); virStoragePoolFree(pool);
if (inputvol) if (inputvol)
@@ -585,7 +581,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr origpool = NULL; virStoragePoolPtr origpool = NULL;
virStorageVolPtr origvol = NULL, newvol = NULL; virStorageVolPtr origvol = NULL, newvol = NULL;
const char *name = NULL; const char *name = NULL;
char *origxml = NULL; g_autofree char *origxml = NULL;
xmlChar *newxml = NULL; xmlChar *newxml = NULL;
bool ret = false; bool ret = false;
unsigned int flags = 0; unsigned int flags = 0;
@@ -632,7 +628,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(origxml);
xmlFree(newxml); xmlFree(newxml);
if (origvol) if (origvol)
virStorageVolFree(origvol); virStorageVolFree(origvol);
@@ -1680,7 +1675,7 @@ static bool
cmdVolPath(vshControl *ctl, const vshCmd *cmd) cmdVolPath(vshControl *ctl, const vshCmd *cmd)
{ {
virStorageVolPtr vol; virStorageVolPtr vol;
char * StorageVolPath; g_autofree char *StorageVolPath = NULL;
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false; return false;
@@ -1691,7 +1686,6 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd)
} }
vshPrint(ctl, "%s\n", StorageVolPath); vshPrint(ctl, "%s\n", StorageVolPath);
VIR_FREE(StorageVolPath);
virStorageVolFree(vol); virStorageVolFree(vol);
return true; return true;
} }

View File

@@ -81,7 +81,7 @@ virshCatchDisconnect(virConnectPtr conn,
vshControl *ctl = opaque; vshControl *ctl = opaque;
const char *str = "unknown reason"; const char *str = "unknown reason";
virErrorPtr error; virErrorPtr error;
char *uri; g_autofree char *uri = NULL;
virErrorPreserveLast(&error); virErrorPreserveLast(&error);
uri = virConnectGetURI(conn); uri = virConnectGetURI(conn);
@@ -101,7 +101,6 @@ virshCatchDisconnect(virConnectPtr conn,
break; break;
} }
vshError(ctl, _(str), NULLSTR(uri)); vshError(ctl, _(str), NULLSTR(uri));
VIR_FREE(uri);
virErrorRestore(&error); virErrorRestore(&error);
disconnected++; disconnected++;