mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
tools: use g_autofree more
Remove some obvious uses of VIR_FREE in favor of automatic cleanup. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
4ad60f9b29
commit
9e79904b1a
@ -1213,7 +1213,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
virDomainInfo info;
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
virSecurityModel secmodel;
|
||||
virSecurityLabelPtr seclabel;
|
||||
int persistent = 0;
|
||||
bool ret = true;
|
||||
int autostart;
|
||||
@ -1301,6 +1300,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
} else {
|
||||
/* Only print something if a security model is active */
|
||||
if (secmodel.model[0] != '\0') {
|
||||
g_autofree virSecurityLabelPtr seclabel = NULL;
|
||||
vshPrint(ctl, "%-15s %s\n", _("Security model:"), secmodel.model);
|
||||
vshPrint(ctl, "%-15s %s\n", _("Security DOI:"), secmodel.doi);
|
||||
|
||||
@ -1308,15 +1308,12 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
seclabel = g_new0(virSecurityLabel, 1);
|
||||
|
||||
if (virDomainGetSecurityLabel(dom, seclabel) == -1) {
|
||||
VIR_FREE(seclabel);
|
||||
return false;
|
||||
} else {
|
||||
if (seclabel->label[0] != '\0')
|
||||
vshPrint(ctl, "%-15s %s (%s)\n", _("Security label:"),
|
||||
seclabel->label, seclabel->enforcing ? "enforcing" : "permissive");
|
||||
}
|
||||
|
||||
VIR_FREE(seclabel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *from = NULL;
|
||||
char *buffer;
|
||||
g_autofree char *buffer = NULL;
|
||||
int rv;
|
||||
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||
bool current = vshCommandOptBool(cmd, "current");
|
||||
@ -404,8 +404,6 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
|
||||
else
|
||||
rv = virDomainAttachDevice(dom, buffer);
|
||||
|
||||
VIR_FREE(buffer);
|
||||
|
||||
if (rv < 0) {
|
||||
vshError(ctl, _("Failed to attach device from %s"), from);
|
||||
return false;
|
||||
@ -2364,7 +2362,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
|
||||
const char *path = NULL;
|
||||
int abort_flags = 0;
|
||||
const char *xml = NULL;
|
||||
char *xmlstr = NULL;
|
||||
g_autofree char *xmlstr = NULL;
|
||||
bool print_xml = vshCommandOptBool(cmd, "print-xml");
|
||||
virTypedParameterPtr params = NULL;
|
||||
virshBlockJobWaitData *bjWait = NULL;
|
||||
@ -2567,7 +2565,6 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(xmlstr);
|
||||
virTypedParamsFree(params, nparams);
|
||||
virshBlockJobWaitFree(bjWait);
|
||||
return ret;
|
||||
@ -5624,7 +5621,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
|
||||
bool ret = false;
|
||||
bool created = false;
|
||||
bool generated = false;
|
||||
char *mime = NULL;
|
||||
g_autofree char *mime = NULL;
|
||||
virshControl *priv = ctl->privData;
|
||||
virshStreamCallbackData cbdata;
|
||||
|
||||
@ -5688,7 +5685,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
|
||||
unlink(file);
|
||||
if (generated)
|
||||
VIR_FREE(file);
|
||||
VIR_FREE(mime);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -7432,9 +7428,8 @@ cmdGuestvcpus(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, "%-15s: %s\n", params[i].field, str);
|
||||
VIR_FREE(str);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8305,7 +8300,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
const char *from = NULL;
|
||||
char *buffer;
|
||||
g_autofree char *buffer = NULL;
|
||||
unsigned int flags = 0;
|
||||
virshControl *priv = ctl->privData;
|
||||
|
||||
@ -8322,7 +8317,6 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
|
||||
dom = virDomainDefineXMLFlags(priv->conn, buffer, flags);
|
||||
else
|
||||
dom = virDomainDefineXML(priv->conn, buffer);
|
||||
VIR_FREE(buffer);
|
||||
|
||||
if (!dom) {
|
||||
vshError(ctl, _("Failed to define domain from %s"), from);
|
||||
@ -10340,7 +10334,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
g_autoptr(virshDomain) dom = NULL;
|
||||
bool ret = false;
|
||||
char *guest_agent_cmd = NULL;
|
||||
g_autofree char *guest_agent_cmd = NULL;
|
||||
char *result = NULL;
|
||||
int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT;
|
||||
int judge = 0;
|
||||
@ -10405,7 +10399,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(result);
|
||||
VIR_FREE(guest_agent_cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -11185,7 +11178,7 @@ doMigrate(void *opaque)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "migrate-disks", &opt) < 0)
|
||||
goto out;
|
||||
if (opt) {
|
||||
char **val = NULL;
|
||||
g_autofree char **val = NULL;
|
||||
|
||||
val = g_strsplit(opt, ",", 0);
|
||||
|
||||
@ -11194,28 +11187,22 @@ doMigrate(void *opaque)
|
||||
&maxparams,
|
||||
VIR_MIGRATE_PARAM_MIGRATE_DISKS,
|
||||
(const char **)val) < 0) {
|
||||
VIR_FREE(val);
|
||||
goto save_error;
|
||||
}
|
||||
|
||||
VIR_FREE(val);
|
||||
}
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "comp-methods", &opt) < 0)
|
||||
goto out;
|
||||
if (opt) {
|
||||
char **val = g_strsplit(opt, ",", 0);
|
||||
g_autofree char **val = g_strsplit(opt, ",", 0);
|
||||
|
||||
if (virTypedParamsAddStringList(¶ms,
|
||||
&nparams,
|
||||
&maxparams,
|
||||
VIR_MIGRATE_PARAM_COMPRESSION,
|
||||
(const char **)val) < 0) {
|
||||
VIR_FREE(val);
|
||||
goto save_error;
|
||||
}
|
||||
|
||||
VIR_FREE(val);
|
||||
}
|
||||
|
||||
if ((rv = vshCommandOptInt(ctl, cmd, "comp-mt-level", &intOpt)) < 0) {
|
||||
@ -11257,7 +11244,7 @@ doMigrate(void *opaque)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "xml", &opt) < 0)
|
||||
goto out;
|
||||
if (opt) {
|
||||
char *xml;
|
||||
g_autofree char *xml = NULL;
|
||||
|
||||
if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) {
|
||||
vshError(ctl, _("cannot read file '%s'"), opt);
|
||||
@ -11266,16 +11253,14 @@ doMigrate(void *opaque)
|
||||
|
||||
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||
VIR_MIGRATE_PARAM_DEST_XML, xml) < 0) {
|
||||
VIR_FREE(xml);
|
||||
goto save_error;
|
||||
}
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "persistent-xml", &opt) < 0)
|
||||
goto out;
|
||||
if (opt) {
|
||||
char *xml;
|
||||
g_autofree char *xml = NULL;
|
||||
|
||||
if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) {
|
||||
vshError(ctl, _("cannot read file '%s'"), opt);
|
||||
@ -11284,10 +11269,8 @@ doMigrate(void *opaque)
|
||||
|
||||
if (virTypedParamsAddString(¶ms, &nparams, &maxparams,
|
||||
VIR_MIGRATE_PARAM_PERSIST_XML, xml) < 0) {
|
||||
VIR_FREE(xml);
|
||||
goto save_error;
|
||||
}
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
if ((rv = vshCommandOptInt(ctl, cmd, "auto-converge-initial", &intOpt)) < 0) {
|
||||
|
@ -412,7 +412,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
int autostart;
|
||||
int persistent = -1;
|
||||
int active = -1;
|
||||
char *bridge = NULL;
|
||||
g_autofree char *bridge = NULL;
|
||||
|
||||
if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
|
||||
return false;
|
||||
@ -441,7 +441,6 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
if (bridge)
|
||||
vshPrint(ctl, "%-15s %s\n", _("Bridge:"), bridge);
|
||||
|
||||
VIR_FREE(bridge);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1500,7 +1499,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
|
||||
virNetworkPortPtr port = NULL;
|
||||
const char *from = NULL;
|
||||
bool ret = false;
|
||||
char *buffer = NULL;
|
||||
g_autofree char *buffer = NULL;
|
||||
g_autoptr(virshNetwork) network = NULL;
|
||||
unsigned int flags = 0;
|
||||
|
||||
@ -1533,7 +1532,6 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
VIR_FREE(buffer);
|
||||
if (port)
|
||||
virNetworkPortFree(port);
|
||||
return ret;
|
||||
|
@ -516,7 +516,7 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
|
||||
{
|
||||
virNWFilterBindingPtr binding;
|
||||
const char *from = NULL;
|
||||
char *buffer;
|
||||
g_autofree char *buffer = NULL;
|
||||
unsigned int flags = 0;
|
||||
virshControl *priv = ctl->privData;
|
||||
|
||||
@ -530,7 +530,6 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
|
||||
return false;
|
||||
|
||||
binding = virNWFilterBindingCreateXML(priv->conn, buffer, flags);
|
||||
VIR_FREE(buffer);
|
||||
|
||||
if (!binding) {
|
||||
vshError(ctl, _("Failed to create network filter from %s"), from);
|
||||
|
@ -73,7 +73,7 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED,
|
||||
vshControl *ctl = opaque;
|
||||
const char *str = "unknown reason";
|
||||
virErrorPtr error;
|
||||
char *uri = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
|
||||
if (reason == VIR_CONNECT_CLOSE_REASON_CLIENT)
|
||||
return;
|
||||
@ -97,8 +97,6 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn G_GNUC_UNUSED,
|
||||
}
|
||||
|
||||
vshError(ctl, _(str), NULLSTR(uri));
|
||||
VIR_FREE(uri);
|
||||
|
||||
virErrorRestore(&error);
|
||||
}
|
||||
|
||||
@ -183,7 +181,7 @@ static const vshCmdInfo info_uri[] = {
|
||||
static bool
|
||||
cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
||||
{
|
||||
char *uri;
|
||||
g_autofree char *uri = NULL;
|
||||
vshAdmControl *priv = ctl->privData;
|
||||
|
||||
uri = virAdmConnectGetURI(priv->conn);
|
||||
@ -193,7 +191,6 @@ cmdURI(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
||||
}
|
||||
|
||||
vshPrint(ctl, "%s\n", uri);
|
||||
VIR_FREE(uri);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -328,7 +325,7 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
||||
int nsrvs = 0;
|
||||
size_t i;
|
||||
bool ret = false;
|
||||
char *uri = NULL;
|
||||
g_autofree char *uri = NULL;
|
||||
virAdmServerPtr *srvs = NULL;
|
||||
vshAdmControl *priv = ctl->privData;
|
||||
g_autoptr(vshTable) table = NULL;
|
||||
@ -365,7 +362,6 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
|
||||
virAdmServerFree(srvs[i]);
|
||||
VIR_FREE(srvs);
|
||||
}
|
||||
VIR_FREE(uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -702,9 +698,8 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
vshAdmClientTransportToString(virAdmClientGetTransport(clnt)));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
@ -56,7 +56,7 @@ void virHostMsgCheck(const char *prefix,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
char *msg;
|
||||
g_autofree char *msg = NULL;
|
||||
|
||||
if (quiet)
|
||||
return;
|
||||
@ -66,7 +66,6 @@ void virHostMsgCheck(const char *prefix,
|
||||
va_end(args);
|
||||
|
||||
fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg);
|
||||
VIR_FREE(msg);
|
||||
}
|
||||
|
||||
static bool virHostMsgWantEscape(void)
|
||||
@ -114,7 +113,7 @@ void virHostMsgFail(virHostValidateLevel level,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
char *msg;
|
||||
g_autofree char *msg = NULL;
|
||||
|
||||
if (quiet)
|
||||
return;
|
||||
@ -129,7 +128,6 @@ void virHostMsgFail(virHostValidateLevel level,
|
||||
else
|
||||
fprintf(stdout, "%s (%s)\n",
|
||||
_(failMessages[level]), msg);
|
||||
VIR_FREE(msg);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user