Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/conf/domain_audit.c | 121 ++++++++++---------------------
src/conf/node_device_util.c | 49 +++++--------
src/conf/nwfilter_conf.c | 55 +++++---------
src/conf/virnetworkobj.c | 85 ++++++++--------------
src/conf/virnetworkportdef.c | 12 +--
src/conf/virnwfilterbindingobj.c | 22 ++----
src/conf/virnwfilterobj.c | 19 ++---
src/conf/virstorageobj.c | 23 ++----
8 files changed, 129 insertions(+), 257 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 82cf6ab749..ae875188bd 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -300,9 +300,9 @@ virDomainAuditNetDevice(virDomainDef *vmDef, virDomainNetDef *netDef,
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
char macstr[VIR_MAC_STRING_BUFLEN];
- char *vmname;
- char *dev_name = NULL;
- char *rdev;
+ g_autofree char *vmname = NULL;
+ g_autofree char *dev_name = NULL;
+ g_autofree char *rdev = NULL;
const char *virt = virDomainAuditGetVirtType(vmDef);
virUUIDFormat(vmDef->uuid, uuidstr);
@@ -312,17 +312,12 @@ virDomainAuditNetDevice(virDomainDef *vmDef, virDomainNetDef
*netDef,
if (!(vmname = virAuditEncode("vm", vmDef->name)) ||
!(dev_name = virAuditEncode("path", device))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
"virt=%s resrc=net reason=open %s uuid=%s net=%s %s rdev=%s",
virt, vmname, uuidstr, macstr, dev_name, VIR_AUDIT_STR(rdev));
-
- cleanup:
- VIR_FREE(vmname);
- VIR_FREE(dev_name);
- VIR_FREE(rdev);
}
/**
@@ -339,9 +334,9 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
- char *address = NULL;
- char *device = NULL;
+ g_autofree char *vmname = NULL;
+ g_autofree char *address = NULL;
+ g_autofree char *device = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virDomainHostdevSubsysUSB *usbsrc = &hostdev->source.subsys.u.usb;
@@ -371,7 +366,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
/* Follow virDomainAuditDisk && virDomainAuditGenericDev
* and don't audit the networked device.
*/
- goto cleanup;
+ return;
} else {
virDomainHostdevSubsysSCSIHost *scsihostsrc = &scsisrc->u.host;
@@ -392,12 +387,12 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef
*hostdev,
default:
VIR_WARN("Unexpected hostdev type while encoding audit message:
%d",
hostdev->source.subsys.type);
- goto cleanup;
+ return;
}
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(address)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -413,7 +408,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
if (!(device = virAuditEncode("disk",
VIR_AUDIT_STR(hostdev->source.caps.u.storage.block)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -425,7 +420,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
if (!(device = virAuditEncode("chardev",
VIR_AUDIT_STR(hostdev->source.caps.u.misc.chardev)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -436,7 +431,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev,
default:
VIR_WARN("Unexpected hostdev type while encoding audit message:
%d",
hostdev->source.caps.type);
- goto cleanup;
+ return;
}
break;
@@ -444,13 +439,8 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef
*hostdev,
default:
VIR_WARN("Unexpected hostdev mode while encoding audit message: %d",
hostdev->mode);
- goto cleanup;
+ return;
}
-
- cleanup:
- VIR_FREE(vmname);
- VIR_FREE(device);
- VIR_FREE(address);
}
@@ -468,9 +458,9 @@ virDomainAuditRedirdev(virDomainObj *vm, virDomainRedirdevDef
*redirdev,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
- char *address = NULL;
- char *device = NULL;
+ g_autofree char *vmname = NULL;
+ g_autofree char *address = NULL;
+ g_autofree char *device = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -486,12 +476,12 @@ virDomainAuditRedirdev(virDomainObj *vm, virDomainRedirdevDef
*redirdev,
default:
VIR_WARN("Unexpected redirdev bus while encoding audit message: %d",
redirdev->bus);
- goto cleanup;
+ return;
}
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(address)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -499,11 +489,6 @@ virDomainAuditRedirdev(virDomainObj *vm, virDomainRedirdevDef
*redirdev,
virt, reason, vmname, uuidstr,
virDomainRedirdevBusTypeToString(redirdev->bus),
device);
-
- cleanup:
- VIR_FREE(vmname);
- VIR_FREE(device);
- VIR_FREE(address);
}
@@ -522,9 +507,9 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
+ g_autofree char *vmname = NULL;
char *path = NULL;
- char *device = NULL;
+ g_autofree char *device = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -538,7 +523,7 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
path = tpm->data.passthrough.source->data.file.path;
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -549,7 +534,7 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
path = tpm->data.emulator.source->data.nix.path;
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -560,7 +545,7 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
path = tpm->data.external.source->data.nix.path;
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
@@ -571,10 +556,6 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
default:
break;
}
-
- cleanup:
- VIR_FREE(vmname);
- VIR_FREE(device);
}
@@ -596,9 +577,9 @@ virDomainAuditCgroup(virDomainObj *vm, virCgroup *cgroup,
const char *reason, const char *extra, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
- char *controller = NULL;
- char *detail;
+ g_autofree char *vmname = NULL;
+ g_autofree char *controller = NULL;
+ g_autofree char *detail = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -616,10 +597,6 @@ virDomainAuditCgroup(virDomainObj *vm, virCgroup *cgroup,
"virt=%s resrc=cgroup reason=%s %s uuid=%s %s class=%s",
virt, reason, vmname, uuidstr,
detail ? detail : "cgroup=?", extra);
-
- VIR_FREE(vmname);
- VIR_FREE(controller);
- VIR_FREE(detail);
}
/**
@@ -639,14 +616,12 @@ virDomainAuditCgroupMajor(virDomainObj *vm, virCgroup *cgroup,
const char *reason, int maj, const char *name,
const char *perms, bool success)
{
- char *extra;
+ g_autofree char *extra = NULL;
extra = g_strdup_printf("major category=%s maj=%02X acl=%s",
name, maj, perms);
virDomainAuditCgroup(vm, cgroup, reason, extra, success);
-
- VIR_FREE(extra);
}
/**
@@ -666,9 +641,9 @@ virDomainAuditCgroupPath(virDomainObj *vm, virCgroup *cgroup,
const char *reason, const char *path, const char *perms,
int rc)
{
- char *detail;
- char *rdev;
- char *extra = NULL;
+ g_autofree char *detail = NULL;
+ g_autofree char *rdev = NULL;
+ g_autofree char *extra = NULL;
/* Nothing to audit for regular files. */
if (rc > 0)
@@ -678,18 +653,13 @@ virDomainAuditCgroupPath(virDomainObj *vm, virCgroup *cgroup,
if (!(detail = virAuditEncode("path", path))) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
extra = g_strdup_printf("path %s rdev=%s acl=%s",
detail, VIR_AUDIT_STR(rdev), perms);
virDomainAuditCgroup(vm, cgroup, reason, extra, rc == 0);
-
- cleanup:
- VIR_FREE(extra);
- VIR_FREE(detail);
- VIR_FREE(rdev);
}
/**
@@ -709,7 +679,7 @@ virDomainAuditResource(virDomainObj *vm, const char *resource,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
+ g_autofree char *vmname = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -722,8 +692,6 @@ virDomainAuditResource(virDomainObj *vm, const char *resource,
"virt=%s resrc=%s reason=%s %s uuid=%s old-%s=%lld new-%s=%lld",
virt, resource, reason, vmname, uuidstr,
resource, oldval, resource, newval);
-
- VIR_FREE(vmname);
}
void
@@ -756,7 +724,7 @@ virDomainAuditLifecycle(virDomainObj *vm, const char *op,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
+ g_autofree char *vmname = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -769,8 +737,6 @@ virDomainAuditLifecycle(virDomainObj *vm, const char *op,
VIR_AUDIT(VIR_AUDIT_RECORD_MACHINE_CONTROL, success,
"virt=%s op=%s reason=%s %s uuid=%s vm-pid=%lld",
virt, op, reason, vmname, uuidstr, (long long)vm->pid);
-
- VIR_FREE(vmname);
}
@@ -851,7 +817,7 @@ virDomainAuditInit(virDomainObj *vm,
ino_t pidns)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
+ g_autofree char *vmname = NULL;
const char *virt = virDomainAuditGetVirtType(vm->def);
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -865,8 +831,6 @@ virDomainAuditInit(virDomainObj *vm,
"virt=%s op=init %s uuid=%s vm-pid=%lld init-pid=%lld
pid-ns=%lld",
virt, vmname, uuidstr, (long long)vm->pid, (long long)initpid,
(long long)pidns);
-
- VIR_FREE(vmname);
}
void
@@ -879,7 +843,7 @@ void
virDomainAuditSecurityLabel(virDomainObj *vm, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname;
+ g_autofree char *vmname = NULL;
size_t i;
const char *virt = virDomainAuditGetVirtType(vm->def);
@@ -897,8 +861,6 @@ virDomainAuditSecurityLabel(virDomainObj *vm, bool success)
VIR_AUDIT_STR(vm->def->seclabels[i]->imagelabel),
VIR_AUDIT_STR(vm->def->seclabels[i]->model));
}
-
- VIR_FREE(vmname);
}
void
@@ -907,16 +869,16 @@ virDomainAuditShmem(virDomainObj *vm,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *vmname = virAuditEncode("vm", vm->def->name);
+ g_autofree char *vmname = virAuditEncode("vm", vm->def->name);
const char *srcpath = virDomainChrSourceDefGetPath(def->server.chr);
const char *virt = virDomainAuditGetVirtType(vm->def);
- char *shmpath = NULL;
+ g_autofree char *shmpath = NULL;
virUUIDFormat(vm->def->uuid, uuidstr);
if (!vmname) {
VIR_WARN("OOM while encoding audit message");
- goto cleanup;
+ return;
}
shmpath = g_strdup_printf("/dev/shm/%s", def->name);
@@ -936,11 +898,6 @@ virDomainAuditShmem(virDomainObj *vm,
"virt=%s resrc=shmem reason=%s %s uuid=%s size=%llu
path=%s",
virt, reason, vmname, uuidstr, def->size, VIR_AUDIT_STR(shmpath));
}
-
- cleanup:
- VIR_FREE(vmname);
- VIR_FREE(shmpath);
- return;
}
diff --git a/src/conf/node_device_util.c b/src/conf/node_device_util.c
index dfec1a91ce..c2fa73afc1 100644
--- a/src/conf/node_device_util.c
+++ b/src/conf/node_device_util.c
@@ -78,7 +78,7 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
{
unsigned int parent_host;
char *name = NULL;
- char *parent_hoststr = NULL;
+ g_autofree char *parent_hoststr = NULL;
bool skip_capable_check = false;
VIR_DEBUG("parent='%s', wwnn='%s' wwpn='%s'",
@@ -91,27 +91,27 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
fchost->parent_wwpn))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot find parent using provided wwnn/wwpn"));
- goto cleanup;
+ return name;
}
} else if (fchost->parent_fabric_wwn) {
if (!(parent_hoststr =
virVHBAGetHostByFabricWWN(NULL, fchost->parent_fabric_wwn))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot find parent using provided fabric_wwn"));
- goto cleanup;
+ return name;
}
} else {
if (!(parent_hoststr = virVHBAFindVportHost(NULL))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("'parent' for vHBA not specified, and "
"cannot find one on this host"));
- goto cleanup;
+ return name;
}
skip_capable_check = true;
}
if (virSCSIHostGetNumber(parent_hoststr, &parent_host) < 0)
- goto cleanup;
+ return name;
/* NOTE:
* We do not save the parent_hoststr in fchost->parent since
@@ -125,23 +125,21 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
virReportError(VIR_ERR_XML_ERROR,
_("parent '%s' specified for vHBA does not
exist"),
parent_hoststr);
- goto cleanup;
+ return name;
}
if (virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
VPORT_CREATE) < 0)
- goto cleanup;
+ return name;
/* Let's ensure the device was created */
virWaitForDevices();
if (!(name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
ignore_value(virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
VPORT_DELETE));
- goto cleanup;
+ return name;
}
- cleanup:
- VIR_FREE(parent_hoststr);
return name;
}
@@ -160,11 +158,10 @@ int
virNodeDeviceDeleteVport(virConnectPtr conn,
virStorageAdapterFCHost *fchost)
{
- char *name = NULL;
- char *scsi_host_name = NULL;
+ g_autofree char *name = NULL;
+ g_autofree char *scsi_host_name = NULL;
unsigned int parent_host;
- char *vhba_parent = NULL;
- int ret = -1;
+ g_autofree char *vhba_parent = NULL;
VIR_DEBUG("conn=%p parent='%s', managed='%d' wwnn='%s'
wwpn='%s'",
conn, NULLSTR(fchost->parent), fchost->managed,
@@ -179,7 +176,7 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to find fc_host for wwnn='%s' and
wwpn='%s'"),
fchost->wwnn, fchost->wwpn);
- goto cleanup;
+ return -1;
}
scsi_host_name = g_strdup_printf("scsi_%s", name);
@@ -193,36 +190,28 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
* was the same as the scsi_host - meaning we have a pool
* backed to an HBA, so there won't be a vHBA to delete */
if (STREQ(scsi_host_name, fchost->parent)) {
- ret = 0;
- goto cleanup;
+ return 0;
}
if (virSCSIHostGetNumber(fchost->parent, &parent_host) < 0)
- goto cleanup;
+ return -1;
} else {
if (!(vhba_parent = virNodeDeviceGetParentName(conn, scsi_host_name)))
- goto cleanup;
+ return -1;
/* If the parent is not a scsi_host, then this is a pool backed
* directly to an HBA and there's no vHBA to remove - so we're done */
if (!STRPREFIX(vhba_parent, "scsi_host")) {
- ret = 0;
- goto cleanup;
+ return 0;
}
if (virSCSIHostGetNumber(vhba_parent, &parent_host) < 0)
- goto cleanup;
+ return -1;
}
if (virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
VPORT_DELETE) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- VIR_FREE(name);
- VIR_FREE(vhba_parent);
- VIR_FREE(scsi_host_name);
- return ret;
+ return 0;
}
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 9a95ae6c12..e5ea45b0b7 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2375,10 +2375,10 @@ virNWFilterRuleDefFixup(virNWFilterRuleDef *rule)
static virNWFilterRuleDef *
virNWFilterRuleParse(xmlNodePtr node)
{
- char *action;
- char *direction;
- char *prio;
- char *statematch;
+ g_autofree char *action = NULL;
+ g_autofree char *direction = NULL;
+ g_autofree char *prio = NULL;
+ g_autofree char *statematch = NULL;
bool found;
int found_i = 0;
int priority;
@@ -2476,17 +2476,11 @@ virNWFilterRuleParse(xmlNodePtr node)
virNWFilterRuleDefFixup(ret);
- cleanup:
- VIR_FREE(prio);
- VIR_FREE(action);
- VIR_FREE(direction);
- VIR_FREE(statematch);
-
return ret;
err_exit:
g_clear_pointer(&ret, virNWFilterRuleDefFree);
- goto cleanup;
+ return ret;
}
@@ -2521,7 +2515,7 @@ virNWFilterIsAllowedChain(const char *chainname)
{
virNWFilterChainSuffixType i;
const char *name;
- char *msg;
+ g_autofree char *msg = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool printed = false;
@@ -2559,7 +2553,6 @@ virNWFilterIsAllowedChain(const char *chainname)
msg = virBufferContentAndReset(&buf);
virReportError(VIR_ERR_INVALID_ARG, "%s", msg);
- VIR_FREE(msg);
return NULL;
}
@@ -2570,9 +2563,9 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
{
virNWFilterDef *ret;
xmlNodePtr curr = ctxt->node;
- char *uuid = NULL;
- char *chain = NULL;
- char *chain_pri_s = NULL;
+ g_autofree char *uuid = NULL;
+ g_autofree char *chain = NULL;
+ g_autofree char *chain_pri_s = NULL;
virNWFilterEntry *entry;
int chain_priority;
const char *name_prefix;
@@ -2641,7 +2634,6 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
"%s", _("malformed uuid element"));
goto cleanup;
}
- VIR_FREE(uuid);
}
curr = curr->children;
@@ -2671,16 +2663,10 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
curr = curr->next;
}
- VIR_FREE(chain);
- VIR_FREE(chain_pri_s);
-
return ret;
cleanup:
virNWFilterDefFree(ret);
- VIR_FREE(chain);
- VIR_FREE(uuid);
- VIR_FREE(chain_pri_s);
return NULL;
}
@@ -2707,24 +2693,21 @@ virNWFilterSaveConfig(const char *configDir,
virNWFilterDef *def)
{
int ret = -1;
- char *xml;
+ g_autofree char *xml = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *configFile = NULL;
+ g_autofree char *configFile = NULL;
if (!(xml = virNWFilterDefFormat(def)))
- goto cleanup;
+ return ret;
if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
- goto cleanup;
+ return ret;
virUUIDFormat(def->uuid, uuidstr);
ret = virXMLSaveFile(configFile,
virXMLPickShellSafeComment(def->name, uuidstr),
"nwfilter-edit", xml);
- cleanup:
- VIR_FREE(configFile);
- VIR_FREE(xml);
return ret;
}
@@ -2733,23 +2716,19 @@ int
virNWFilterDeleteDef(const char *configDir,
virNWFilterDef *def)
{
- int ret = -1;
- char *configFile = NULL;
+ g_autofree char *configFile = NULL;
if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
- goto error;
+ return -1;
if (unlink(configFile) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot remove config for %s"),
def->name);
- goto error;
+ return -1;
}
- ret = 0;
- error:
- VIR_FREE(configFile);
- return ret;
+ return 0;
}
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 635d2ec0b0..c75ecf3a04 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -260,8 +260,7 @@ virNetworkObjMacMgrAdd(virNetworkObj *obj,
const virMacAddr *mac)
{
char macStr[VIR_MAC_STRING_BUFLEN];
- char *file = NULL;
- int ret = -1;
+ g_autofree char *file = NULL;
if (!obj->macmap)
return 0;
@@ -269,18 +268,15 @@ virNetworkObjMacMgrAdd(virNetworkObj *obj,
virMacAddrFormat(mac, macStr);
if (!(file = virMacMapFileName(dnsmasqStateDir, obj->def->bridge)))
- goto cleanup;
+ return -1;
if (virMacMapAdd(obj->macmap, domain, macStr) < 0)
- goto cleanup;
+ return -1;
if (virMacMapWriteFile(obj->macmap, file) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(file);
- return ret;
+ return 0;
}
@@ -291,8 +287,7 @@ virNetworkObjMacMgrDel(virNetworkObj *obj,
const virMacAddr *mac)
{
char macStr[VIR_MAC_STRING_BUFLEN];
- char *file = NULL;
- int ret = -1;
+ g_autofree char *file = NULL;
if (!obj->macmap)
return 0;
@@ -300,18 +295,15 @@ virNetworkObjMacMgrDel(virNetworkObj *obj,
virMacAddrFormat(mac, macStr);
if (!(file = virMacMapFileName(dnsmasqStateDir, obj->def->bridge)))
- goto cleanup;
+ return -1;
if (virMacMapRemove(obj->macmap, domain, macStr) < 0)
- goto cleanup;
+ return -1;
if (virMacMapWriteFile(obj->macmap, file) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(file);
- return ret;
+ return 0;
}
@@ -819,20 +811,16 @@ virNetworkObjSaveStatus(const char *statusDir,
virNetworkObj *obj,
virNetworkXMLOption *xmlopt)
{
- int ret = -1;
int flags = 0;
- char *xml;
+ g_autofree char *xml = NULL;
if (!(xml = virNetworkObjFormat(obj, xmlopt, flags)))
- goto cleanup;
+ return -1;
if (virNetworkSaveXML(statusDir, obj->def, xml))
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(xml);
- return ret;
+ return 0;
}
@@ -953,29 +941,30 @@ virNetworkLoadConfig(virNetworkObjList *nets,
const char *name,
virNetworkXMLOption *xmlopt)
{
- char *configFile = NULL, *autostartLink = NULL;
+ g_autofree char *configFile = NULL;
+ g_autofree char *autostartLink = NULL;
g_autoptr(virNetworkDef) def = NULL;
virNetworkObj *obj;
bool saveConfig = false;
int autostart;
if ((configFile = virNetworkConfigFile(configDir, name)) == NULL)
- goto error;
+ return NULL;
if ((autostartLink = virNetworkConfigFile(autostartDir, name)) == NULL)
- goto error;
+ return NULL;
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
- goto error;
+ return NULL;
if (!(def = virNetworkDefParse(NULL, configFile, xmlopt, false)))
- goto error;
+ return NULL;
if (STRNEQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network config filename '%s'"
" does not match network name '%s'"),
configFile, def->name);
- goto error;
+ return NULL;
}
switch ((virNetworkForwardType) def->forward.type) {
@@ -1005,7 +994,7 @@ virNetworkLoadConfig(virNetworkObjList *nets,
case VIR_NETWORK_FORWARD_LAST:
default:
virReportEnumRangeError(virNetworkForwardType, def->forward.type);
- goto error;
+ return NULL;
}
/* The network didn't have a UUID so we generated a new one, and
@@ -1016,25 +1005,17 @@ virNetworkLoadConfig(virNetworkObjList *nets,
if (saveConfig &&
virNetworkSaveConfig(configDir, def, xmlopt) < 0) {
- goto error;
+ return NULL;
}
if (!(obj = virNetworkObjAssignDef(nets, def, 0)))
- goto error;
+ return NULL;
def = NULL;
obj->autostart = (autostart == 1);
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
-
return obj;
-
- error:
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
- return NULL;
}
@@ -1110,14 +1091,13 @@ virNetworkObjDeleteConfig(const char *configDir,
const char *autostartDir,
virNetworkObj *obj)
{
- char *configFile = NULL;
- char *autostartLink = NULL;
- int ret = -1;
+ g_autofree char *configFile = NULL;
+ g_autofree char *autostartLink = NULL;
if (!(configFile = virNetworkConfigFile(configDir, obj->def->name)))
- goto error;
+ return -1;
if (!(autostartLink = virNetworkConfigFile(autostartDir, obj->def->name)))
- goto error;
+ return -1;
/* Not fatal if this doesn't work */
unlink(autostartLink);
@@ -1127,15 +1107,10 @@ virNetworkObjDeleteConfig(const char *configDir,
virReportSystemError(errno,
_("cannot remove config file '%s'"),
configFile);
- goto error;
+ return -1;
}
- ret = 0;
-
- error:
- VIR_FREE(configFile);
- VIR_FREE(autostartLink);
- return ret;
+ return 0;
}
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index 035e3fe758..37f5376976 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -415,22 +415,18 @@ virNetworkPortDefDeleteStatus(virNetworkPortDef *def,
const char *dir)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *path;
- int ret = -1;
+ g_autofree char *path = NULL;
virUUIDFormat(def->uuid, uuidstr);
if (!(path = virNetworkPortDefConfigFile(dir, uuidstr)))
- goto cleanup;
+ return -1;
if (unlink(path) < 0 && errno != ENOENT) {
virReportSystemError(errno,
_("Unable to delete %s"), path);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- VIR_FREE(path);
- return ret;
+ return 0;
}
diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c
index 6e67c5c7b6..862f825422 100644
--- a/src/conf/virnwfilterbindingobj.c
+++ b/src/conf/virnwfilterbindingobj.c
@@ -146,8 +146,8 @@ int
virNWFilterBindingObjSave(const virNWFilterBindingObj *obj,
const char *statusDir)
{
- char *filename;
- char *xml = NULL;
+ g_autofree char *filename = NULL;
+ g_autofree char *xml = NULL;
int ret = -1;
if (!(filename = virNWFilterBindingObjConfigFile(statusDir,
@@ -155,22 +155,19 @@ virNWFilterBindingObjSave(const virNWFilterBindingObj *obj,
return -1;
if (!(xml = virNWFilterBindingObjFormat(obj)))
- goto cleanup;
+ return -1;
if (g_mkdir_with_parents(statusDir, 0777) < 0) {
virReportSystemError(errno,
_("cannot create config directory '%s'"),
statusDir);
- goto cleanup;
+ return -1;
}
ret = virXMLSaveFile(filename,
obj->def->portdevname,
"nwfilter-binding-create",
xml);
- cleanup:
- VIR_FREE(xml);
- VIR_FREE(filename);
return ret;
}
@@ -179,8 +176,7 @@ int
virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
const char *statusDir)
{
- char *filename;
- int ret = -1;
+ g_autofree char *filename = NULL;
if (!(filename = virNWFilterBindingObjConfigFile(statusDir,
obj->def->portdevname)))
@@ -191,14 +187,10 @@ virNWFilterBindingObjDelete(const virNWFilterBindingObj *obj,
virReportSystemError(errno,
_("Unable to remove status '%s' for nwfilter
binding %s'"),
filename, obj->def->portdevname);
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- VIR_FREE(filename);
- return ret;
+ return 0;
}
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index e8dfe66b3c..2e75e90cf1 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -281,21 +281,14 @@ static bool
virNWFilterDefEqual(const virNWFilterDef *def1,
virNWFilterDef *def2)
{
- bool ret = false;
- char *xml1 = NULL;
- char *xml2 = NULL;
+ g_autofree char *xml1 = NULL;
+ g_autofree char *xml2 = NULL;
if (!(xml1 = virNWFilterDefFormat(def1)) ||
!(xml2 = virNWFilterDefFormat(def2)))
- goto cleanup;
-
- ret = STREQ(xml1, xml2);
+ return false;
- cleanup:
- VIR_FREE(xml1);
- VIR_FREE(xml2);
-
- return ret;
+ return STREQ(xml1, xml2);
}
@@ -573,7 +566,7 @@ virNWFilterObjListLoadConfig(virNWFilterObjList *nwfilters,
{
virNWFilterDef *def = NULL;
virNWFilterObj *obj;
- char *configFile = NULL;
+ g_autofree char *configFile = NULL;
if (!(configFile = virFileBuildPath(configDir, name, ".xml")))
goto error;
@@ -597,11 +590,9 @@ virNWFilterObjListLoadConfig(virNWFilterObjList *nwfilters,
if (!(obj = virNWFilterObjListAssignDef(nwfilters, def)))
goto error;
- VIR_FREE(configFile);
return obj;
error:
- VIR_FREE(configFile);
virNWFilterDefFree(def);
return NULL;
}
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 98d9e0b97e..e6c187e80a 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1088,9 +1088,8 @@ static int
getSCSIHostNumber(virStorageAdapterSCSIHost *scsi_host,
unsigned int *hostnum)
{
- int ret = -1;
unsigned int num;
- char *name = NULL;
+ g_autofree char *name = NULL;
if (scsi_host->has_parent) {
virPCIDeviceAddress *addr = &scsi_host->parentaddr;
@@ -1101,20 +1100,17 @@ getSCSIHostNumber(virStorageAdapterSCSIHost *scsi_host,
addr->slot,
addr->function,
unique_id)))
- goto cleanup;
+ return -1;
if (virSCSIHostGetNumber(name, &num) < 0)
- goto cleanup;
+ return -1;
} else {
if (virSCSIHostGetNumber(scsi_host->name, &num) < 0)
- goto cleanup;
+ return -1;
}
*hostnum = num;
- ret = 0;
- cleanup:
- VIR_FREE(name);
- return ret;
+ return 0;
}
@@ -1147,9 +1143,9 @@ matchFCHostToSCSIHost(virStorageAdapterFCHost *fchost,
{
virConnectPtr conn = NULL;
bool ret = false;
- char *name = NULL;
- char *scsi_host_name = NULL;
- char *parent_name = NULL;
+ g_autofree char *name = NULL;
+ g_autofree char *scsi_host_name = NULL;
+ g_autofree char *parent_name = NULL;
/* If we have a parent defined, get its hostnum, and compare to the
* scsi_hostnum. If they are the same, then we have a match
@@ -1202,9 +1198,6 @@ matchFCHostToSCSIHost(virStorageAdapterFCHost *fchost,
*/
cleanup:
- VIR_FREE(name);
- VIR_FREE(parent_name);
- VIR_FREE(scsi_host_name);
virConnectClose(conn);
return ret;
}
--
2.33.0