[libvirt] [PATCH v2 0/6] Alter domain_conf to make use of autofree

v1: https://www.redhat.com/archives/libvir-list/2019-February/msg01160.html Changes since v1: * Push patch 1 * Split patch 2 to follow code review guidance: * (Patch1) Pull out virDomainEmulatorPinDefParseXML changes to use VIR_STEAL_PTR * (Patch2) Use VIR_AUTOPTR(virBitmap) * (Patch3) Handle a couple cases where goto's no longer necessary * Drop Patch 3 * Split Patch 4 to follow code review guidance: * (Patch4) Remove unused variables * (Patch5) Just use VIR_AUTOFREE * (Patch6) Handle the removal of goto logic that's no longer necessary John Ferlan (6): conf: Rework virDomainEmulatorPinDefParseXML conf: Use VIR_AUTOPTR(virBitmap) in domain_conf conf: Clean up some unnecessary goto paths conf: Remove a few unused variables in domain_conf conf: Use VIR_AUTOFREE in domain_conf conf: Clean up some unnecessary goto paths src/conf/domain_conf.c | 1937 ++++++++++++++-------------------------- 1 file changed, 676 insertions(+), 1261 deletions(-) -- 2.20.1

In preparation for using auto free mechanism, change to using the VIR_STEAL_PTR on @def to @ret and of course be sure to properly clean up @def in cleanup. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ceeb247ef4..542d53e709 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18398,6 +18398,7 @@ static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { virBitmapPtr def = NULL; + virBitmapPtr ret = NULL; char *tmp = NULL; if (!(tmp = virXMLPropString(node, "cpuset"))) { @@ -18412,14 +18413,15 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) if (virBitmapIsAllClear(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - virBitmapFree(def); - def = NULL; goto cleanup; } + VIR_STEAL_PTR(ret, def); + cleanup: + virBitmapFree(def); VIR_FREE(tmp); - return def; + return ret; } -- 2.20.1

On Wed, Feb 20, 2019 at 01:33:59PM -0500, John Ferlan wrote:
In preparation for using auto free mechanism, change to using the VIR_STEAL_PTR on @def to @ret and of course be sure to properly clean up @def in cleanup.
Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>

Let's make use of the auto __cleanup capabilities for virBitmapPtr. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 542d53e709..f27af65d80 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1803,8 +1803,8 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, virBitmapPtr autoCpuset) { int maxvcpus = virDomainDefGetVcpusMax(def); - virBitmapPtr allcpumap = NULL; size_t i; + VIR_AUTOPTR(virBitmap) allcpumap = NULL; if (hostcpus < 0) return -1; @@ -1831,7 +1831,6 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen); } - virBitmapFree(allcpumap); return i; } @@ -2988,7 +2987,7 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, size_t i; ssize_t nxt = -1; virDomainIOThreadIDDefPtr iothrid = NULL; - virBitmapPtr thrmap = NULL; + VIR_AUTOPTR(virBitmap) thrmap = NULL; /* Same value (either 0 or some number), then we have none to fill in or * the iothreadid array was filled from the XML @@ -3029,7 +3028,6 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, retval = 0; error: - virBitmapFree(thrmap); return retval; } @@ -18327,9 +18325,9 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, { int ret = -1; virDomainIOThreadIDDefPtr iothrid; - virBitmapPtr cpumask = NULL; unsigned int iothreadid; char *tmp = NULL; + VIR_AUTOPTR(virBitmap) cpumask = NULL; if (!(tmp = virXMLPropString(node, "iothread"))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -18385,7 +18383,6 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, cleanup: VIR_FREE(tmp); - virBitmapFree(cpumask); return ret; } @@ -18397,9 +18394,9 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { - virBitmapPtr def = NULL; virBitmapPtr ret = NULL; char *tmp = NULL; + VIR_AUTOPTR(virBitmap) def = NULL; if (!(tmp = virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -18419,7 +18416,6 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) VIR_STEAL_PTR(ret, def); cleanup: - virBitmapFree(def); VIR_FREE(tmp); return ret; } @@ -18780,11 +18776,11 @@ virDomainThreadSchedParseHelper(xmlNodePtr node, virDomainDefPtr def) { ssize_t next = -1; - virBitmapPtr map = NULL; virDomainThreadSchedParamPtr sched; virProcessSchedPolicy policy; int priority; int ret = -1; + VIR_AUTOPTR(virBitmap) map = NULL; if (!(map = virDomainSchedulerParse(node, name, &policy, &priority))) goto cleanup; @@ -18807,7 +18803,6 @@ virDomainThreadSchedParseHelper(xmlNodePtr node, ret = 0; cleanup: - virBitmapFree(map); return ret; } @@ -19511,12 +19506,12 @@ virDomainCachetuneDefParse(virDomainDefPtr def, { xmlNodePtr oldnode = ctxt->node; xmlNodePtr *nodes = NULL; - virBitmapPtr vcpus = NULL; virResctrlAllocPtr alloc = NULL; virDomainResctrlDefPtr resctrl = NULL; ssize_t i = 0; int n; int ret = -1; + VIR_AUTOPTR(virBitmap) vcpus = NULL; ctxt->node = node; @@ -19576,7 +19571,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, ctxt->node = oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - virBitmapFree(vcpus); VIR_FREE(nodes); return ret; } @@ -19730,9 +19724,9 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, { xmlNodePtr oldnode = ctxt->node; xmlNodePtr *nodes = NULL; - virBitmapPtr vcpus = NULL; virResctrlAllocPtr alloc = NULL; virDomainResctrlDefPtr resctrl = NULL; + VIR_AUTOPTR(virBitmap) vcpus = NULL; ssize_t i = 0; int n; @@ -19791,7 +19785,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ctxt->node = oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - virBitmapFree(vcpus); VIR_FREE(nodes); return ret; } -- 2.20.1

On Wed, Feb 20, 2019 at 01:34:00PM -0500, John Ferlan wrote:
Let's make use of the auto __cleanup capabilities for virBitmapPtr.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- Reviewed-by: Erik Skultety <eskultet@redhat.com>

Now that we're using VIR_AUTOPTR(virBitmap) there's a couple of methods that we can clean up some now unnecessary goto paths. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f27af65d80..ddcb76f05d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2983,7 +2983,6 @@ static int virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, unsigned int iothreads) { - int retval = -1; size_t i; ssize_t nxt = -1; virDomainIOThreadIDDefPtr iothrid = NULL; @@ -2997,7 +2996,7 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, /* iothread's are numbered starting at 1, account for that */ if (!(thrmap = virBitmapNew(iothreads + 1))) - goto error; + return -1; virBitmapSetAll(thrmap); /* Clear 0 since we don't use it, then mark those which are @@ -3009,26 +3008,23 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, /* resize array */ if (VIR_REALLOC_N(def->iothreadids, iothreads) < 0) - goto error; + return -1; /* Populate iothreadids[] using the set bit number from thrmap */ while (def->niothreadids < iothreads) { if ((nxt = virBitmapNextSetBit(thrmap, nxt)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to populate iothreadids")); - goto error; + return -1; } if (VIR_ALLOC(iothrid) < 0) - goto error; + return -1; iothrid->iothread_id = nxt; iothrid->autofill = true; def->iothreadids[def->niothreadids++] = iothrid; } - retval = 0; - - error: - return retval; + return 0; } @@ -18779,31 +18775,27 @@ virDomainThreadSchedParseHelper(xmlNodePtr node, virDomainThreadSchedParamPtr sched; virProcessSchedPolicy policy; int priority; - int ret = -1; VIR_AUTOPTR(virBitmap) map = NULL; if (!(map = virDomainSchedulerParse(node, name, &policy, &priority))) - goto cleanup; + return -1; while ((next = virBitmapNextSetBit(map, next)) > -1) { if (!(sched = func(def, next))) - goto cleanup; + return -1; if (sched->policy != VIR_PROC_POLICY_NONE) { virReportError(VIR_ERR_XML_DETAIL, _("%ssched attributes 'vcpus' must not overlap"), name); - goto cleanup; + return -1; } sched->policy = policy; sched->priority = priority; } - ret = 0; - - cleanup: - return ret; + return 0; } -- 2.20.1

On Wed, Feb 20, 2019 at 01:34:01PM -0500, John Ferlan wrote:
Now that we're using VIR_AUTOPTR(virBitmap) there's a couple of methods that we can clean up some now unnecessary goto paths.
Signed-off-by: John Ferlan <jferlan@redhat.com> ---
Every reviewer has their own preferences. Truth to be told I agree with your comment to v1, to me, this feels a bit detached and it was actually harder to track than if this was part of the previous patch, but it is what it is: Reviewed-by: Erik Skultety <eskultet@redhat.com>

In preparation for VIR_AUTOFREE usage, let's remove a couple of unused variables so that clang compilations won't fail. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ddcb76f05d..1ec521a35d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7138,7 +7138,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, xmlNodePtr alias = NULL; xmlNodePtr boot = NULL; xmlNodePtr rom = NULL; - char *type = NULL; char *romenabled = NULL; char *rombar = NULL; char *aliasStr = NULL; @@ -7224,7 +7223,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, cleanup: if (ret < 0) virDomainDeviceInfoClear(info); - VIR_FREE(type); VIR_FREE(rombar); VIR_FREE(romenabled); VIR_FREE(aliasStr); @@ -13012,7 +13010,6 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *type = NULL; char *path = NULL; char *model = NULL; char *backend = NULL; @@ -13093,7 +13090,6 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(type); VIR_FREE(path); VIR_FREE(model); VIR_FREE(backend); @@ -18548,7 +18544,7 @@ virDomainHugepagesParseXML(xmlNodePtr node, { int ret = -1; xmlNodePtr oldnode = ctxt->node; - char *unit = NULL, *nodeset = NULL; + char *nodeset = NULL; ctxt->node = node; @@ -18576,7 +18572,6 @@ virDomainHugepagesParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(unit); VIR_FREE(nodeset); ctxt->node = oldnode; return ret; -- 2.20.1

On Wed, Feb 20, 2019 at 01:34:02PM -0500, John Ferlan wrote:
In preparation for VIR_AUTOFREE usage, let's remove a couple of unused variables so that clang compilations won't fail.
Signed-off-by: John Ferlan <jferlan@redhat.com> ---
I guess that if there were more, Clang would have complained at some point given the adjustments. Reviewed-by: Erik Skultety <eskultet@redhat.com>

Let's make use of the auto __cleanup capabilities for VIR_FREE consumers. In some cases adding or removing blank lines for readability. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 1080 +++++++++++++--------------------------- 1 file changed, 347 insertions(+), 733 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1ec521a35d..98a35b0296 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1099,11 +1099,11 @@ static int virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, xmlNodePtr node) { - char *name = NULL; - char *state = NULL; int state_type; int name_type; int ret = -1; + VIR_AUTOFREE(char *) name = NULL; + VIR_AUTOFREE(char *) state = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", @@ -1161,8 +1161,6 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, ret = 0; cleanup: - VIR_FREE(name); - VIR_FREE(state); return ret; } @@ -1171,8 +1169,8 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt) { size_t i; int ret = -1; - xmlNodePtr *nodes = NULL; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; if ((n = virXPathNodeSet("./keywrap/cipher", ctxt, &nodes)) < 0) return n; @@ -1194,7 +1192,6 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt) cleanup: if (ret < 0) VIR_FREE(def->keywrap); - VIR_FREE(nodes); return ret; } @@ -1267,10 +1264,10 @@ static int virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { - char *str = NULL; int ret = -1; int val; virDomainVirtioOptionsPtr res; + VIR_AUTOFREE(char *) str = NULL; if (*virtio || !driver) return 0; @@ -1302,7 +1299,6 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, ret = 0; cleanup: - VIR_FREE(str); return ret; } @@ -1344,8 +1340,8 @@ static int virDomainBlkioDeviceParseXML(xmlNodePtr root, virBlkioDevicePtr dev) { - char *c = NULL; xmlNodePtr node; + VIR_AUTOFREE(char *) c = NULL; node = root->children; while (node) { @@ -1410,7 +1406,6 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, return 0; error: - VIR_FREE(c); VIR_FREE(dev->path); return -1; } @@ -5338,8 +5333,8 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, void *data) { virHashTablePtr bootHash = data; - char *order = NULL; int ret = -1; + VIR_AUTOFREE(char *) order = NULL; if (info->bootIndex == 0) return 0; @@ -5368,7 +5363,6 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, ret = 0; cleanup: - VIR_FREE(order); return ret; } @@ -6889,8 +6883,8 @@ static int virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virDomainDeviceUSBMasterPtr master) { - char *startport; int ret = -1; + VIR_AUTOFREE(char *) startport = NULL; memset(master, 0, sizeof(*master)); @@ -6906,7 +6900,6 @@ virDomainDeviceUSBMasterParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(startport); return ret; } @@ -6914,9 +6907,9 @@ static int virDomainDeviceBootParseXML(xmlNodePtr node, virDomainDeviceInfoPtr info) { - char *order; - char *loadparm = NULL; int ret = -1; + VIR_AUTOFREE(char *) order = NULL; + VIR_AUTOFREE(char *) loadparm = NULL; if (!(order = virXMLPropString(node, "order"))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -6950,8 +6943,6 @@ virDomainDeviceBootParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(order); - VIR_FREE(loadparm); return ret; } @@ -6960,8 +6951,8 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node, virDomainDeviceISAAddressPtr addr) { int ret = -1; - char *iobase; - char *irq; + VIR_AUTOFREE(char *) iobase = NULL; + VIR_AUTOFREE(char *) irq = NULL; memset(addr, 0, sizeof(*addr)); @@ -6984,8 +6975,6 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(iobase); - VIR_FREE(irq); return ret; } @@ -6995,7 +6984,7 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, virDomainDeviceDimmAddressPtr addr) { int ret = -1; - char *tmp = NULL; + VIR_AUTOFREE(char *) tmp = NULL; if (!(tmp = virXMLPropString(node, "slot")) || virStrToLong_uip(tmp, NULL, 10, &addr->slot) < 0) { @@ -7012,15 +7001,11 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, _("invalid dimm base address '%s'"), tmp); goto cleanup; } - - VIR_FREE(tmp); } ret = 0; cleanup: - VIR_FREE(tmp); - return ret; } @@ -7030,7 +7015,7 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, virDomainDeviceInfoPtr info) { int ret = -1; - char *type = virXMLPropString(address, "type"); + VIR_AUTOFREE(char *) type = virXMLPropString(address, "type"); if (type) { if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) { @@ -7107,7 +7092,6 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, ret = 0; cleanup: - VIR_FREE(type); return ret; } @@ -7138,10 +7122,10 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, xmlNodePtr alias = NULL; xmlNodePtr boot = NULL; xmlNodePtr rom = NULL; - char *romenabled = NULL; - char *rombar = NULL; - char *aliasStr = NULL; int ret = -1; + VIR_AUTOFREE(char *) romenabled = NULL; + VIR_AUTOFREE(char *) rombar = NULL; + VIR_AUTOFREE(char *) aliasStr = NULL; virDomainDeviceInfoClear(info); @@ -7223,9 +7207,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, cleanup: if (ret < 0) virDomainDeviceInfoClear(info); - VIR_FREE(rombar); - VIR_FREE(romenabled); - VIR_FREE(aliasStr); return ret; } @@ -7254,9 +7235,9 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, int ret = -1; bool got_product, got_vendor; xmlNodePtr cur; - char *startupPolicy = NULL; - char *autoAddress; virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb; + VIR_AUTOFREE(char *) startupPolicy = NULL; + VIR_AUTOFREE(char *) autoAddress = NULL; if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) { def->startupPolicy = @@ -7265,16 +7246,13 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown startup policy '%s'"), startupPolicy); - VIR_FREE(startupPolicy); goto out; } - VIR_FREE(startupPolicy); } if ((autoAddress = virXMLPropString(node, "autoAddress"))) { if (STREQ(autoAddress, "yes")) usbsrc->autoAddress = true; - VIR_FREE(autoAddress); } /* Product can validly be 0, so we need some extra help to determine @@ -7286,24 +7264,22 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "vendor")) { - char *vendor = virXMLPropString(cur, "id"); + VIR_AUTOFREE(char *) vendor = virXMLPropString(cur, "id"); if (vendor) { got_vendor = true; if (virStrToLong_ui(vendor, NULL, 0, &usbsrc->vendor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vendor id %s"), vendor); - VIR_FREE(vendor); goto out; } - VIR_FREE(vendor); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb vendor needs id")); goto out; } } else if (virXMLNodeNameEqual(cur, "product")) { - char* product = virXMLPropString(cur, "id"); + VIR_AUTOFREE(char *) product = virXMLPropString(cur, "id"); if (product) { got_product = true; @@ -7312,27 +7288,24 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse product %s"), product); - VIR_FREE(product); goto out; } - VIR_FREE(product); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb product needs id")); goto out; } } else if (virXMLNodeNameEqual(cur, "address")) { - char *bus, *device; + VIR_AUTOFREE(char *) bus = NULL; + VIR_AUTOFREE(char *) device = NULL; bus = virXMLPropString(cur, "bus"); if (bus) { if (virStrToLong_ui(bus, NULL, 0, &usbsrc->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse bus %s"), bus); - VIR_FREE(bus); goto out; } - VIR_FREE(bus); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb address needs bus id")); @@ -7345,10 +7318,8 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse device %s"), device); - VIR_FREE(device); goto out; } - VIR_FREE(device); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb address needs device id")); @@ -7442,14 +7413,13 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && virXMLNodeNameEqual(cur, "state")) { /* Legacy back-compat. Don't add any more attributes here */ - char *devaddr = virXMLPropString(cur, "devaddr"); + VIR_AUTOFREE(char *) devaddr = virXMLPropString(cur, "devaddr"); if (devaddr && virDomainParseLegacyDeviceAddress(devaddr, &def->info->addr.pci) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse devaddr parameter '%s'"), devaddr); - VIR_FREE(devaddr); goto out; } def->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -7480,9 +7450,9 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, size_t *nhosts) { int ret = -1; - char *transport = NULL; - char *port = NULL; virStorageNetHostDef host; + VIR_AUTOFREE(char *) transport = NULL; + VIR_AUTOFREE(char *) port = NULL; memset(&host, 0, sizeof(host)); host.transport = VIR_STORAGE_NET_HOST_TRANS_TCP; @@ -7536,8 +7506,6 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, cleanup: virStorageNetHostDefClear(&host); - VIR_FREE(transport); - VIR_FREE(port); return ret; } @@ -7569,8 +7537,10 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, int ret = -1; bool got_address = false, got_adapter = false; xmlNodePtr cur; - char *bus = NULL, *target = NULL, *unit = NULL; virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; + VIR_AUTOFREE(char *) bus = NULL; + VIR_AUTOFREE(char *) target = NULL; + VIR_AUTOFREE(char *) unit = NULL; cur = sourcenode->children; while (cur != NULL) { @@ -7645,9 +7615,6 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, ret = 0; cleanup: - VIR_FREE(bus); - VIR_FREE(target); - VIR_FREE(unit); return ret; } @@ -7727,8 +7694,8 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr scsisrc, xmlXPathContextPtr ctxt) { - char *protocol = NULL; int ret = -1; + VIR_AUTOFREE(char *) protocol = NULL; if ((protocol = virXMLPropString(sourcenode, "protocol"))) { scsisrc->protocol = @@ -7747,7 +7714,6 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc); cleanup: - VIR_FREE(protocol); return ret; } @@ -7755,10 +7721,10 @@ static int virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevDefPtr def) { - char *protocol = NULL; - char *wwpn = NULL; virDomainHostdevSubsysSCSIVHostPtr hostsrc = &def->source.subsys.u.scsi_host; int ret = -1; + VIR_AUTOFREE(char *) protocol = NULL; + VIR_AUTOFREE(char *) wwpn = NULL; if (!(protocol = virXMLPropString(sourcenode, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -7800,8 +7766,6 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, ret = 0; cleanup: - VIR_FREE(wwpn); - VIR_FREE(protocol); return ret; } @@ -7811,9 +7775,9 @@ virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def, { int ret = -1; unsigned char uuid[VIR_UUID_BUFLEN] = {0}; - char *uuidxml = NULL; xmlNodePtr node = NULL; virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev; + VIR_AUTOFREE(char *) uuidxml = NULL; if (!(node = virXPathNode("./source/address", ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -7837,7 +7801,6 @@ virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def, virUUIDFormat(uuid, mdevsrc->uuidstr); ret = 0; cleanup: - VIR_FREE(uuidxml); return ret; } @@ -7849,17 +7812,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, unsigned int flags) { xmlNodePtr sourcenode; - char *managed = NULL; - char *sgio = NULL; - char *rawio = NULL; - char *backendStr = NULL; - char *model = NULL; - char *display = NULL; int backend; int ret = -1; virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi; virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev; + VIR_AUTOFREE(char *) managed = NULL; + VIR_AUTOFREE(char *) sgio = NULL; + VIR_AUTOFREE(char *) rawio = NULL; + VIR_AUTOFREE(char *) backendStr = NULL; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) display = NULL; /* @managed can be read from the xml document - it is always an * attribute of the toplevel element, no matter what type of @@ -8019,12 +7982,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(managed); - VIR_FREE(sgio); - VIR_FREE(rawio); - VIR_FREE(backendStr); - VIR_FREE(model); - VIR_FREE(display); return ret; } @@ -8032,12 +7989,14 @@ static virNetDevIPAddrPtr virDomainNetIPParseXML(xmlNodePtr node) { /* Parse the prefix in every case */ - virNetDevIPAddrPtr ip = NULL, ret = NULL; - char *prefixStr = NULL; + virNetDevIPAddrPtr ret = NULL; unsigned int prefixValue = 0; - char *familyStr = NULL; int family = AF_UNSPEC; - char *address = NULL, *peer = NULL; + VIR_AUTOFREE(virNetDevIPAddrPtr) ip = NULL; + VIR_AUTOFREE(char *) prefixStr = NULL; + VIR_AUTOFREE(char *) familyStr = NULL; + VIR_AUTOFREE(char *) address = NULL; + VIR_AUTOFREE(char *) peer = NULL; if (!(address = virXMLPropString(node, "address"))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -8085,11 +8044,6 @@ virDomainNetIPParseXML(xmlNodePtr node) VIR_STEAL_PTR(ret, ip); cleanup: - VIR_FREE(prefixStr); - VIR_FREE(familyStr); - VIR_FREE(address); - VIR_FREE(peer); - VIR_FREE(ip); return ret; } @@ -8104,12 +8058,12 @@ virDomainNetIPInfoParseXML(const char *source, xmlXPathContextPtr ctxt, virNetDevIPInfoPtr def) { - xmlNodePtr *nodes = NULL; - virNetDevIPAddrPtr ip = NULL; virNetDevIPRoutePtr route = NULL; int nnodes; int ret = -1; size_t i; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; + VIR_AUTOFREE(virNetDevIPAddrPtr) ip = NULL; if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0) goto cleanup; @@ -8134,9 +8088,7 @@ virDomainNetIPInfoParseXML(const char *source, cleanup: if (ret < 0) virNetDevIPInfoClear(def); - VIR_FREE(ip); virNetDevIPRouteFree(route); - VIR_FREE(nodes); return ret; } @@ -8147,8 +8099,8 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, { virNetDevCoalescePtr ret = NULL; xmlNodePtr save = NULL; - char *str = NULL; unsigned long long tmp = 0; + VIR_AUTOFREE(char *) str = NULL; save = ctxt->node; ctxt->node = node; @@ -8164,10 +8116,8 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, virReportError(VIR_ERR_XML_DETAIL, _("cannot parse value '%s' for coalesce parameter"), str); - VIR_FREE(str); goto error; } - VIR_FREE(str); if (tmp > UINT32_MAX) { virReportError(VIR_ERR_OVERFLOW, @@ -8179,7 +8129,6 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, ret->rx_max_coalesced_frames = tmp; cleanup: - VIR_FREE(str); ctxt->node = save; return ret; @@ -8554,8 +8503,9 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, { size_t i = 0, j; int n; - xmlNodePtr *list = NULL, saved_node; + xmlNodePtr saved_node; virCapsHostPtr host = &caps->host; + VIR_AUTOFREE(xmlNodePtr *) list = NULL; /* Check args and save context */ if (def == NULL || ctxt == NULL) @@ -8593,7 +8543,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, } def->nseclabels = n; ctxt->node = saved_node; - VIR_FREE(list); /* libvirt versions prior to 0.10.0 support just a single seclabel element * in guest's XML and model attribute can be suppressed if type is none or @@ -8648,7 +8597,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, virSecurityLabelDefFree(def->seclabels[i - 1]); VIR_FREE(def->seclabels); def->nseclabels = 0; - VIR_FREE(list); return -1; } @@ -8663,8 +8611,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, size_t nseclabels = 0; int n; size_t i, j; - xmlNodePtr *list = NULL; char *model, *relabel, *label, *labelskip; + VIR_AUTOFREE(xmlNodePtr *) list = NULL; if ((n = virXPathNodeSet("./seclabel", ctxt, &list)) < 0) goto error; @@ -8732,7 +8680,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, goto error; } } - VIR_FREE(list); *nseclabels_rtn = nseclabels; *seclabels_rtn = seclabels; @@ -8743,7 +8690,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, for (i = 0; i < nseclabels; i++) virSecurityDeviceLabelDefFree(seclabels[i]); VIR_FREE(seclabels); - VIR_FREE(list); return -1; } @@ -8786,10 +8732,10 @@ virDomainLeaseDefParseXML(xmlNodePtr node) { virDomainLeaseDefPtr def; xmlNodePtr cur; - char *lockspace = NULL; - char *key = NULL; - char *path = NULL; - char *offset = NULL; + VIR_AUTOFREE(char *) lockspace = NULL; + VIR_AUTOFREE(char *) key = NULL; + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) offset = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -8834,11 +8780,6 @@ virDomainLeaseDefParseXML(xmlNodePtr node) VIR_STEAL_PTR(def->path, path); cleanup: - VIR_FREE(lockspace); - VIR_FREE(key); - VIR_FREE(path); - VIR_FREE(offset); - return def; error: @@ -8851,9 +8792,9 @@ static int virDomainDiskSourcePoolDefParse(xmlNodePtr node, virStorageSourcePoolDefPtr *srcpool) { - char *mode = NULL; virStorageSourcePoolDefPtr source; int ret = -1; + VIR_AUTOFREE(char *) mode = NULL; *srcpool = NULL; @@ -8890,7 +8831,6 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, cleanup: virStorageSourcePoolDefFree(source); - VIR_FREE(mode); return ret; } @@ -8901,11 +8841,11 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virStorageSourcePtr src, unsigned int flags) { - char *protocol = NULL; - char *haveTLS = NULL; - char *tlsCfg = NULL; int tlsCfgVal; int ret = -1; + VIR_AUTOFREE(char *) protocol = NULL; + VIR_AUTOFREE(char *) haveTLS = NULL; + VIR_AUTOFREE(char *) tlsCfg = NULL; if (!(protocol = virXMLPropString(node, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -8982,9 +8922,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(tlsCfg); - VIR_FREE(haveTLS); - VIR_FREE(protocol); return ret; } @@ -9139,11 +9076,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, { xmlNodePtr save_ctxt = ctxt->node; xmlNodePtr source; - char *type = NULL; - char *format = NULL; - char *idx = NULL; int ret = -1; VIR_AUTOUNREF(virStorageSourcePtr) backingStore = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) format = NULL; + VIR_AUTOFREE(char *) idx = NULL; if (!(ctxt->node = virXPathNode("./backingStore", ctxt))) { ret = 0; @@ -9204,9 +9141,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, ret = 0; cleanup: - VIR_FREE(type); - VIR_FREE(format); - VIR_FREE(idx); ctxt->node = save_ctxt; return ret; } @@ -9302,11 +9236,11 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, virDomainXMLOptionPtr xmlopt) { xmlNodePtr mirrorNode; - char *mirrorFormat = NULL; - char *mirrorType = NULL; - char *ready = NULL; - char *blockJob = NULL; int ret = -1; + VIR_AUTOFREE(char *) mirrorFormat = NULL; + VIR_AUTOFREE(char *) mirrorType = NULL; + VIR_AUTOFREE(char *) ready = NULL; + VIR_AUTOFREE(char *) blockJob = NULL; if (!(def->mirror = virStorageSourceNew())) goto cleanup; @@ -9379,10 +9313,6 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, ret = 0; cleanup: - VIR_FREE(ready); - VIR_FREE(blockJob); - VIR_FREE(mirrorType); - VIR_FREE(mirrorFormat); return ret; } @@ -9391,7 +9321,7 @@ static int virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, xmlNodePtr cur) { - char *tmp; + VIR_AUTOFREE(char *) tmp = NULL; if ((tmp = virXMLPropString(cur, "cyls"))) { if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) { @@ -9428,13 +9358,11 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, tmp); goto error; } - VIR_FREE(tmp); } return 0; error: - VIR_FREE(tmp); return -1; } @@ -9579,8 +9507,8 @@ static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, xmlNodePtr cur) { - char *tmp = NULL; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; def->driverName = virXMLPropString(cur, "name"); @@ -9689,13 +9617,10 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, tmp); goto cleanup; } - VIR_FREE(tmp); ret = 0; cleanup: - VIR_FREE(tmp); - return ret; } @@ -9744,26 +9669,26 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainDiskDefPtr def; xmlNodePtr cur; xmlNodePtr save_ctxt = ctxt->node; - char *tmp = NULL; - char *snapshot = NULL; - char *rawio = NULL; - char *sgio = NULL; bool source = false; - char *target = NULL; - char *bus = NULL; - char *devaddr = NULL; virStorageEncryptionPtr encryption = NULL; - char *serial = NULL; - char *startupPolicy = NULL; - char *tray = NULL; - char *removable = NULL; - char *logical_block_size = NULL; - char *physical_block_size = NULL; - char *wwn = NULL; - char *vendor = NULL; - char *product = NULL; - char *domain_name = NULL; VIR_AUTOPTR(virStorageAuthDef) authdef = NULL; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(char *) snapshot = NULL; + VIR_AUTOFREE(char *) rawio = NULL; + VIR_AUTOFREE(char *) sgio = NULL; + VIR_AUTOFREE(char *) target = NULL; + VIR_AUTOFREE(char *) bus = NULL; + VIR_AUTOFREE(char *) devaddr = NULL; + VIR_AUTOFREE(char *) serial = NULL; + VIR_AUTOFREE(char *) startupPolicy = NULL; + VIR_AUTOFREE(char *) tray = NULL; + VIR_AUTOFREE(char *) removable = NULL; + VIR_AUTOFREE(char *) logical_block_size = NULL; + VIR_AUTOFREE(char *) physical_block_size = NULL; + VIR_AUTOFREE(char *) wwn = NULL; + VIR_AUTOFREE(char *) vendor = NULL; + VIR_AUTOFREE(char *) product = NULL; + VIR_AUTOFREE(char *) domain_name = NULL; if (!(def = virDomainDiskDefNew(xmlopt))) return NULL; @@ -10151,25 +10076,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(tmp); - VIR_FREE(bus); - VIR_FREE(snapshot); - VIR_FREE(rawio); - VIR_FREE(sgio); - VIR_FREE(target); - VIR_FREE(tray); - VIR_FREE(removable); - VIR_FREE(devaddr); - VIR_FREE(serial); virStorageEncryptionFree(encryption); - VIR_FREE(startupPolicy); - VIR_FREE(logical_block_size); - VIR_FREE(physical_block_size); - VIR_FREE(wwn); - VIR_FREE(vendor); - VIR_FREE(product); - VIR_FREE(domain_name); - ctxt->node = save_ctxt; return def; @@ -10210,11 +10117,11 @@ virDomainParseScaledValue(const char *xpath, unsigned long long max, bool required) { - char *xpath_full = NULL; - char *unit = NULL; - char *bytes_str = NULL; int ret = -1; unsigned long long bytes; + VIR_AUTOFREE(char *) xpath_full = NULL; + VIR_AUTOFREE(char *) unit = NULL; + VIR_AUTOFREE(char *) bytes_str = NULL; *val = 0; if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) @@ -10253,9 +10160,6 @@ virDomainParseScaledValue(const char *xpath, *val = bytes; ret = 1; cleanup: - VIR_FREE(bytes_str); - VIR_FREE(xpath_full); - VIR_FREE(unit); return ret; } @@ -10456,27 +10360,27 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainControllerDefPtr def = NULL; int type = 0; xmlNodePtr cur = NULL; - char *typeStr = NULL; - char *idx = NULL; - char *model = NULL; - char *queues = NULL; - char *cmd_per_lun = NULL; - char *max_sectors = NULL; bool processedModel = false; - char *modelName = NULL; bool processedTarget = false; - char *chassisNr = NULL; - char *chassis = NULL; - char *port = NULL; - char *busNr = NULL; - char *targetIndex = NULL; int numaNode = -1; - char *ioeventfd = NULL; - char *portsStr = NULL; int ports = -1; - char *iothread = NULL; xmlNodePtr saved = ctxt->node; int rc; + VIR_AUTOFREE(char *) typeStr = NULL; + VIR_AUTOFREE(char *) idx = NULL; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) queues = NULL; + VIR_AUTOFREE(char *) cmd_per_lun = NULL; + VIR_AUTOFREE(char *) max_sectors = NULL; + VIR_AUTOFREE(char *) modelName = NULL; + VIR_AUTOFREE(char *) chassisNr = NULL; + VIR_AUTOFREE(char *) chassis = NULL; + VIR_AUTOFREE(char *) port = NULL; + VIR_AUTOFREE(char *) busNr = NULL; + VIR_AUTOFREE(char *) targetIndex = NULL; + VIR_AUTOFREE(char *) ioeventfd = NULL; + VIR_AUTOFREE(char *) portsStr = NULL; + VIR_AUTOFREE(char *) iothread = NULL; ctxt->node = node; @@ -10615,20 +10519,18 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt, switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { - def->opts.vioserial.ports = ports; + VIR_AUTOFREE(char *) vectors = virXMLPropString(node, "vectors"); - char *vectors = virXMLPropString(node, "vectors"); + def->opts.vioserial.ports = ports; if (vectors) { int r = virStrToLong_i(vectors, NULL, 10, &def->opts.vioserial.vectors); if (r != 0 || def->opts.vioserial.vectors < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid vectors: %s"), vectors); - VIR_FREE(vectors); goto error; } } - VIR_FREE(vectors); break; } case VIR_DOMAIN_CONTROLLER_TYPE_USB: { @@ -10791,22 +10693,6 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: ctxt->node = saved; - VIR_FREE(typeStr); - VIR_FREE(idx); - VIR_FREE(model); - VIR_FREE(queues); - VIR_FREE(cmd_per_lun); - VIR_FREE(max_sectors); - VIR_FREE(modelName); - VIR_FREE(chassisNr); - VIR_FREE(chassis); - VIR_FREE(port); - VIR_FREE(busNr); - VIR_FREE(targetIndex); - VIR_FREE(ioeventfd); - VIR_FREE(portsStr); - VIR_FREE(iothread); - return def; error: @@ -10835,15 +10721,15 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt, { virDomainFSDefPtr def; xmlNodePtr cur, save_node = ctxt->node; - char *type = NULL; - char *fsdriver = NULL; - char *source = NULL; - char *target = NULL; - char *format = NULL; - char *accessmode = NULL; - char *wrpolicy = NULL; - char *usage = NULL; - char *units = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) fsdriver = NULL; + VIR_AUTOFREE(char *) source = NULL; + VIR_AUTOFREE(char *) target = NULL; + VIR_AUTOFREE(char *) format = NULL; + VIR_AUTOFREE(char *) accessmode = NULL; + VIR_AUTOFREE(char *) wrpolicy = NULL; + VIR_AUTOFREE(char *) usage = NULL; + VIR_AUTOFREE(char *) units = NULL; ctxt->node = node; @@ -10989,16 +10875,6 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: ctxt->node = save_node; - VIR_FREE(type); - VIR_FREE(fsdriver); - VIR_FREE(target); - VIR_FREE(source); - VIR_FREE(accessmode); - VIR_FREE(wrpolicy); - VIR_FREE(usage); - VIR_FREE(units); - VIR_FREE(format); - return def; error: @@ -11020,11 +10896,11 @@ virDomainActualNetDefParseXML(xmlNodePtr node, xmlNodePtr bandwidth_node = NULL; xmlNodePtr vlanNode; xmlNodePtr virtPortNode; - char *type = NULL; - char *mode = NULL; - char *addrtype = NULL; - char *trustGuestRxFilters = NULL; - char *macTableManager = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) mode = NULL; + VIR_AUTOFREE(char *) addrtype = NULL; + VIR_AUTOFREE(char *) trustGuestRxFilters = NULL; + VIR_AUTOFREE(char *) macTableManager = NULL; if (VIR_ALLOC(actual) < 0) return -1; @@ -11123,16 +10999,16 @@ virDomainActualNetDefParseXML(xmlNodePtr node, goto error; } } else if (actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) { - char *class_id = virXPathString("string(./class/@id)", ctxt); + VIR_AUTOFREE(char *) class_id = NULL; + + class_id = virXPathString("string(./class/@id)", ctxt); if (class_id && virStrToLong_ui(class_id, NULL, 10, &actual->class_id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse class id '%s'"), class_id); - VIR_FREE(class_id); goto error; } - VIR_FREE(class_id); } if (actual->type == VIR_DOMAIN_NET_TYPE_BRIDGE || actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -11174,11 +11050,6 @@ virDomainActualNetDefParseXML(xmlNodePtr node, VIR_STEAL_PTR(*def, actual); ret = 0; error: - VIR_FREE(type); - VIR_FREE(mode); - VIR_FREE(addrtype); - VIR_FREE(trustGuestRxFilters); - VIR_FREE(macTableManager); virDomainActualNetDefFree(actual); ctxt->node = save_ctxt; @@ -11221,9 +11092,9 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, { int ret = -1; int tmpVal; - char *tmp = NULL; xmlNodePtr saveNode = ctxt->node; xmlNodePtr cur; + VIR_AUTOFREE(char *) tmp = NULL; ctxt->node = node; @@ -11247,7 +11118,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, tmp); goto cleanup; } - VIR_FREE(tmp); } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing timeout for chardev with " @@ -11260,7 +11130,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def, ret = 0; cleanup: ctxt->node = saveNode; - VIR_FREE(tmp); return ret; } @@ -11280,46 +11149,46 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainHostdevDefPtr hostdev; xmlNodePtr cur; xmlNodePtr tmpNode; - char *macaddr = NULL; - char *type = NULL; - char *network = NULL; - char *portgroup = NULL; - char *bridge = NULL; - char *dev = NULL; - char *ifname = NULL; - char *ifname_guest = NULL; - char *ifname_guest_actual = NULL; - char *script = NULL; - char *address = NULL; - char *port = NULL; - char *localaddr = NULL; - char *localport = NULL; - char *model = NULL; - char *backend = NULL; - char *txmode = NULL; - char *ioeventfd = NULL; - char *event_idx = NULL; - char *queues = NULL; - char *rx_queue_size = NULL; - char *tx_queue_size = NULL; - char *str = NULL; - char *filter = NULL; - char *internal = NULL; - char *devaddr = NULL; - char *mode = NULL; - char *linkstate = NULL; - char *addrtype = NULL; - char *domain_name = NULL; - char *vhostuser_mode = NULL; - char *vhostuser_path = NULL; - char *vhostuser_type = NULL; - char *trustGuestRxFilters = NULL; - char *vhost_path = NULL; virHashTablePtr filterparams = NULL; virDomainActualNetDefPtr actual = NULL; xmlNodePtr oldnode = ctxt->node; virDomainChrSourceReconnectDef reconnect = {0}; int rv, val; + VIR_AUTOFREE(char *) macaddr = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) network = NULL; + VIR_AUTOFREE(char *) portgroup = NULL; + VIR_AUTOFREE(char *) bridge = NULL; + VIR_AUTOFREE(char *) dev = NULL; + VIR_AUTOFREE(char *) ifname = NULL; + VIR_AUTOFREE(char *) ifname_guest = NULL; + VIR_AUTOFREE(char *) ifname_guest_actual = NULL; + VIR_AUTOFREE(char *) script = NULL; + VIR_AUTOFREE(char *) address = NULL; + VIR_AUTOFREE(char *) port = NULL; + VIR_AUTOFREE(char *) localaddr = NULL; + VIR_AUTOFREE(char *) localport = NULL; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) backend = NULL; + VIR_AUTOFREE(char *) txmode = NULL; + VIR_AUTOFREE(char *) ioeventfd = NULL; + VIR_AUTOFREE(char *) event_idx = NULL; + VIR_AUTOFREE(char *) queues = NULL; + VIR_AUTOFREE(char *) rx_queue_size = NULL; + VIR_AUTOFREE(char *) tx_queue_size = NULL; + VIR_AUTOFREE(char *) str = NULL; + VIR_AUTOFREE(char *) filter = NULL; + VIR_AUTOFREE(char *) internal = NULL; + VIR_AUTOFREE(char *) devaddr = NULL; + VIR_AUTOFREE(char *) mode = NULL; + VIR_AUTOFREE(char *) linkstate = NULL; + VIR_AUTOFREE(char *) addrtype = NULL; + VIR_AUTOFREE(char *) domain_name = NULL; + VIR_AUTOFREE(char *) vhostuser_mode = NULL; + VIR_AUTOFREE(char *) vhostuser_path = NULL; + VIR_AUTOFREE(char *) vhostuser_type = NULL; + VIR_AUTOFREE(char *) trustGuestRxFilters = NULL; + VIR_AUTOFREE(char *) vhost_path = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -12067,44 +11936,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: ctxt->node = oldnode; - VIR_FREE(macaddr); - VIR_FREE(network); - VIR_FREE(portgroup); - VIR_FREE(address); - VIR_FREE(port); - VIR_FREE(vhostuser_type); - VIR_FREE(vhostuser_path); - VIR_FREE(vhostuser_mode); - VIR_FREE(ifname); - VIR_FREE(ifname_guest); - VIR_FREE(ifname_guest_actual); - VIR_FREE(dev); virDomainActualNetDefFree(actual); - VIR_FREE(script); - VIR_FREE(bridge); - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(txmode); - VIR_FREE(ioeventfd); - VIR_FREE(event_idx); - VIR_FREE(queues); - VIR_FREE(rx_queue_size); - VIR_FREE(tx_queue_size); - VIR_FREE(str); - VIR_FREE(filter); - VIR_FREE(type); - VIR_FREE(internal); - VIR_FREE(devaddr); - VIR_FREE(mode); - VIR_FREE(linkstate); - VIR_FREE(addrtype); - VIR_FREE(domain_name); - VIR_FREE(trustGuestRxFilters); - VIR_FREE(vhost_path); - VIR_FREE(localaddr); - VIR_FREE(localport); virHashFree(filterparams); - return def; error: @@ -12204,11 +12037,11 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, int ret = -1; xmlNodePtr child; unsigned int port; - char *targetType = virXMLPropString(cur, "type"); - char *targetModel = NULL; - char *addrStr = NULL; - char *portStr = NULL; - char *stateStr = NULL; + VIR_AUTOFREE(char *) targetType = virXMLPropString(cur, "type"); + VIR_AUTOFREE(char *) targetModel = NULL; + VIR_AUTOFREE(char *) addrStr = NULL; + VIR_AUTOFREE(char *) portStr = NULL; + VIR_AUTOFREE(char *) stateStr = NULL; if ((def->targetType = virDomainChrTargetTypeFromString(def->deviceType, @@ -12324,12 +12157,6 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, ret = 0; error: - VIR_FREE(targetType); - VIR_FREE(targetModel); - VIR_FREE(addrStr); - VIR_FREE(portStr); - VIR_FREE(stateStr); - return ret; } @@ -12349,8 +12176,8 @@ typedef enum { static int virDomainChrSourceDefParseMode(xmlNodePtr source) { - char *mode = virXMLPropString(source, "mode"); int ret = -1; + VIR_AUTOFREE(char *) mode = virXMLPropString(source, "mode"); if (!mode || STREQ(mode, "connect")) { ret = VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; @@ -12361,7 +12188,6 @@ virDomainChrSourceDefParseMode(xmlNodePtr source) _("Unknown source mode '%s'"), mode); } - VIR_FREE(mode); return ret; } @@ -12373,8 +12199,8 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, unsigned int flags) { int mode; - char *tmp = NULL; int tmpVal; + VIR_AUTOFREE(char *) tmp = NULL; if ((mode = virDomainChrSourceDefParseMode(source)) < 0) goto error; @@ -12402,7 +12228,6 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, goto error; } def->data.tcp.tlsFromConfig = !!tmpVal; - VIR_FREE(tmp); } if (virDomainChrSourceReconnectDefParseXML(&def->data.tcp.reconnect, @@ -12414,7 +12239,6 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, return 0; error: - VIR_FREE(tmp); return -1; } @@ -12469,7 +12293,7 @@ static int virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def, xmlNodePtr source) { - char *append = NULL; + VIR_AUTOFREE(char *) append = NULL; def->data.file.path = virXMLPropString(source, "path"); @@ -12478,11 +12302,9 @@ virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid append attribute value '%s'"), append); - VIR_FREE(append); return -1; } - VIR_FREE(append); return 0; } @@ -12491,7 +12313,7 @@ static int virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def, xmlNodePtr protocol) { - char *prot = NULL; + VIR_AUTOFREE(char *) prot = NULL; if (def->type != VIR_DOMAIN_CHR_TYPE_TCP) return 0; @@ -12501,11 +12323,9 @@ virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def, virDomainChrTcpProtocolTypeFromString(prot)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown protocol '%s'"), prot); - VIR_FREE(prot); return -1; } - VIR_FREE(prot); return 0; } @@ -12514,7 +12334,7 @@ static int virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def, xmlNodePtr log) { - char *append = NULL; + VIR_AUTOFREE(char *) append = NULL; def->logfile = virXMLPropString(log, "file"); @@ -12523,11 +12343,9 @@ virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid append attribute value '%s'"), append); - VIR_FREE(append); return -1; } - VIR_FREE(append); return 0; } @@ -12775,10 +12593,10 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { xmlNodePtr cur; - char *type = NULL; const char *nodeName; virDomainChrDefPtr def; bool seenTarget = false; + VIR_AUTOFREE(char *) type = NULL; if (!(def = virDomainChrDefNew(xmlopt))) return NULL; @@ -12845,8 +12663,6 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt, } cleanup: - VIR_FREE(type); - return def; error: @@ -12862,10 +12678,10 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { xmlNodePtr cur; - char *mode = NULL; - char *type = NULL; virDomainSmartcardDefPtr def; size_t i; + VIR_AUTOFREE(char *) mode = NULL; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -12977,9 +12793,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, } cleanup: - VIR_FREE(mode); - VIR_FREE(type); - return def; error: @@ -13010,14 +12823,14 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *path = NULL; - char *model = NULL; - char *backend = NULL; - char *version = NULL; virDomainTPMDefPtr def; xmlNodePtr save = ctxt->node; - xmlNodePtr *backends = NULL; int nbackends; + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) backend = NULL; + VIR_AUTOFREE(char *) version = NULL; + VIR_AUTOFREE(xmlNodePtr *) backends = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -13090,11 +12903,6 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(path); - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(backends); - VIR_FREE(version); ctxt->node = save; return def; @@ -13110,7 +12918,7 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { virDomainPanicDefPtr panic; - char *model = NULL; + VIR_AUTOFREE(char *) model = NULL; if (VIR_ALLOC(panic) < 0) return NULL; @@ -13128,7 +12936,6 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xmlopt, } cleanup: - VIR_FREE(model); return panic; error: @@ -13147,9 +12954,9 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt, { xmlNodePtr save = ctxt->node; virDomainInputDefPtr def; - char *evdev = NULL; - char *type = NULL; - char *bus = NULL; + VIR_AUTOFREE(char *) evdev = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) bus = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -13277,10 +13084,6 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(evdev); - VIR_FREE(type); - VIR_FREE(bus); - ctxt->node = save; return def; @@ -13298,7 +13101,7 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { virDomainHubDefPtr def; - char *type = NULL; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -13321,8 +13124,6 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(type); - return def; error: @@ -13337,16 +13138,15 @@ static virDomainTimerDefPtr virDomainTimerDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { - char *name = NULL; - char *present = NULL; - char *tickpolicy = NULL; - char *track = NULL; - char *mode = NULL; - virDomainTimerDefPtr def; xmlNodePtr oldnode = ctxt->node; xmlNodePtr catchup; int ret; + VIR_AUTOFREE(char *) name = NULL; + VIR_AUTOFREE(char *) present = NULL; + VIR_AUTOFREE(char *) tickpolicy = NULL; + VIR_AUTOFREE(char *) track = NULL; + VIR_AUTOFREE(char *) mode = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -13449,11 +13249,6 @@ virDomainTimerDefParseXML(xmlNodePtr node, } cleanup: - VIR_FREE(name); - VIR_FREE(present); - VIR_FREE(tickpolicy); - VIR_FREE(track); - VIR_FREE(mode); ctxt->node = oldnode; return def; @@ -13469,8 +13264,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virDomainGraphicsAuthDefPtr def, int type) { - char *validTo = NULL; - char *connected = virXMLPropString(node, "connected"); + VIR_AUTOFREE(char *) validTo = NULL; + VIR_AUTOFREE(char *) connected = virXMLPropString(node, "connected"); def->passwd = virXMLPropString(node, "passwd"); @@ -13498,11 +13293,9 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse password validity time '%s', expect YYYY-MM-DDTHH:MM:SS"), validTo); - VIR_FREE(validTo); VIR_FREE(def->passwd); return -1; } - VIR_FREE(validTo); tm.tm_year -= 1900; /* Human epoch starts at 0 BC, not 1900BC */ tm.tm_mon--; /* Humans start months at 1, computers at 0 */ @@ -13517,10 +13310,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown connected value %s"), connected); - VIR_FREE(connected); return -1; } - VIR_FREE(connected); /* VNC supports connected='keep' only */ if (type == VIR_DOMAIN_GRAPHICS_TYPE_VNC && @@ -13558,16 +13349,16 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, unsigned int flags) { int ret = -1; - char *type = virXMLPropString(node, "type"); - char *address = virXMLPropString(node, "address"); - char *network = virXMLPropString(node, "network"); - char *socketPath = virXMLPropString(node, "socket"); - char *fromConfig = virXMLPropString(node, "fromConfig"); - char *autoGenerated = virXMLPropString(node, "autoGenerated"); - char *addressCompat = NULL; - char *socketCompat = NULL; const char *graphicsType = virDomainGraphicsTypeToString(graphics->type); int tmp, typeVal; + VIR_AUTOFREE(char *) type = virXMLPropString(node, "type"); + VIR_AUTOFREE(char *) address = virXMLPropString(node, "address"); + VIR_AUTOFREE(char *) network = virXMLPropString(node, "network"); + VIR_AUTOFREE(char *) socketPath = virXMLPropString(node, "socket"); + VIR_AUTOFREE(char *) fromConfig = virXMLPropString(node, "fromConfig"); + VIR_AUTOFREE(char *) autoGenerated = virXMLPropString(node, "autoGenerated"); + VIR_AUTOFREE(char *) addressCompat = NULL; + VIR_AUTOFREE(char *) socketCompat = NULL; if (parent) { addressCompat = virXMLPropString(parent, "listen"); @@ -13692,14 +13483,6 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, error: if (ret < 0) virDomainGraphicsListenDefClear(def); - VIR_FREE(type); - VIR_FREE(address); - VIR_FREE(network); - VIR_FREE(socketPath); - VIR_FREE(fromConfig); - VIR_FREE(autoGenerated); - VIR_FREE(addressCompat); - VIR_FREE(socketCompat); return ret; } @@ -13710,12 +13493,12 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr *listenNodes = NULL; xmlNodePtr save = ctxt->node; virDomainGraphicsListenDef newListen = {0}; - char *socketPath = NULL; int nListens; int ret = -1; + VIR_AUTOFREE(xmlNodePtr *) listenNodes = NULL; + VIR_AUTOFREE(char *) socketPath = NULL; ctxt->node = node; @@ -13739,7 +13522,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, def->nListens++; } - VIR_FREE(listenNodes); } /* If no <listen/> element was found in XML for backward compatibility @@ -13782,8 +13564,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, ret = 0; cleanup: virDomainGraphicsListenDefClear(&newListen); - VIR_FREE(listenNodes); - VIR_FREE(socketPath); ctxt->node = save; return ret; } @@ -13795,12 +13575,12 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - char *port = virXMLPropString(node, "port"); - char *websocket = virXMLPropString(node, "websocket"); - char *websocketGenerated = virXMLPropString(node, "websocketGenerated"); - char *sharePolicy = virXMLPropString(node, "sharePolicy"); - char *autoport = virXMLPropString(node, "autoport"); int ret = -1; + VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) websocket = virXMLPropString(node, "websocket"); + VIR_AUTOFREE(char *) websocketGenerated = virXMLPropString(node, "websocketGenerated"); + VIR_AUTOFREE(char *) sharePolicy = virXMLPropString(node, "sharePolicy"); + VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto cleanup; @@ -13867,11 +13647,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, ret = 0; cleanup: - VIR_FREE(port); - VIR_FREE(autoport); - VIR_FREE(websocket); - VIR_FREE(websocketGenerated); - VIR_FREE(sharePolicy); return ret; } @@ -13882,11 +13657,11 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr save = ctxt->node; - char *enable = NULL; int enableVal; xmlNodePtr glNode; - char *fullscreen = virXMLPropString(node, "fullscreen"); int ret = -1; + VIR_AUTOFREE(char *) fullscreen = virXMLPropString(node, "fullscreen"); + VIR_AUTOFREE(char *) enable = NULL; ctxt->node = node; @@ -13927,8 +13702,6 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, ret = 0; cleanup: - VIR_FREE(fullscreen); - VIR_FREE(enable); ctxt->node = save; return ret; } @@ -13940,11 +13713,11 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - char *port = virXMLPropString(node, "port"); - char *autoport = virXMLPropString(node, "autoport"); - char *replaceUser = virXMLPropString(node, "replaceUser"); - char *multiUser = virXMLPropString(node, "multiUser"); int ret = -1; + VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); + VIR_AUTOFREE(char *) replaceUser = virXMLPropString(node, "replaceUser"); + VIR_AUTOFREE(char *) multiUser = virXMLPropString(node, "multiUser"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto error; @@ -13978,10 +13751,6 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, ret = 0; error: - VIR_FREE(port); - VIR_FREE(autoport); - VIR_FREE(replaceUser); - VIR_FREE(multiUser); return ret; } @@ -13990,8 +13759,8 @@ static int virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, xmlNodePtr node) { - char *fullscreen = virXMLPropString(node, "fullscreen"); int ret = -1; + VIR_AUTOFREE(char *) fullscreen = virXMLPropString(node, "fullscreen"); if (fullscreen != NULL) { if (STREQ(fullscreen, "yes")) { @@ -14011,7 +13780,6 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, ret = 0; cleanup: - VIR_FREE(fullscreen); return ret; } @@ -14023,12 +13791,12 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, unsigned int flags) { xmlNodePtr cur; - char *port = virXMLPropString(node, "port"); - char *tlsPort = virXMLPropString(node, "tlsPort"); - char *autoport = virXMLPropString(node, "autoport"); - char *defaultMode = virXMLPropString(node, "defaultMode"); int defaultModeVal; int ret = -1; + VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) tlsPort = virXMLPropString(node, "tlsPort"); + VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); + VIR_AUTOFREE(char *) defaultMode = virXMLPropString(node, "defaultMode"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto error; @@ -14088,16 +13856,16 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "channel")) { - char *name, *mode; int nameval, modeval; + VIR_AUTOFREE(char *) name = NULL; + VIR_AUTOFREE(char *) mode = NULL; + name = virXMLPropString(cur, "name"); mode = virXMLPropString(cur, "mode"); if (!name || !mode) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice channel missing name/mode")); - VIR_FREE(name); - VIR_FREE(mode); goto error; } @@ -14105,25 +13873,19 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel name %s"), name); - VIR_FREE(name); - VIR_FREE(mode); goto error; } if ((modeval = virDomainGraphicsSpiceChannelModeTypeFromString(mode)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel mode %s"), mode); - VIR_FREE(name); - VIR_FREE(mode); goto error; } - VIR_FREE(name); - VIR_FREE(mode); def->data.spice.channels[nameval] = modeval; } else if (virXMLNodeNameEqual(cur, "image")) { - char *compression = virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression = virXMLPropString(cur, "compression"); if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -14136,15 +13898,13 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice image compression %s"), compression); - VIR_FREE(compression); goto error; } - VIR_FREE(compression); def->data.spice.image = compressionVal; } else if (virXMLNodeNameEqual(cur, "jpeg")) { - char *compression = virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression = virXMLPropString(cur, "compression"); if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -14157,15 +13917,13 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice jpeg compression %s"), compression); - VIR_FREE(compression); goto error; } - VIR_FREE(compression); def->data.spice.jpeg = compressionVal; } else if (virXMLNodeNameEqual(cur, "zlib")) { - char *compression = virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression = virXMLPropString(cur, "compression"); if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -14178,15 +13936,13 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice zlib compression %s"), compression); - VIR_FREE(compression); goto error; } - VIR_FREE(compression); def->data.spice.zlib = compressionVal; } else if (virXMLNodeNameEqual(cur, "playback")) { - char *compression = virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression = virXMLPropString(cur, "compression"); if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -14198,16 +13954,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virTristateSwitchTypeFromString(compression)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice playback compression")); - VIR_FREE(compression); goto error; } - VIR_FREE(compression); def->data.spice.playback = compressionVal; } else if (virXMLNodeNameEqual(cur, "streaming")) { - char *mode = virXMLPropString(cur, "mode"); int modeVal; + VIR_AUTOFREE(char *) mode = virXMLPropString(cur, "mode"); if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -14218,16 +13972,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virDomainGraphicsSpiceStreamingModeTypeFromString(mode)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice streaming mode")); - VIR_FREE(mode); goto error; } - VIR_FREE(mode); def->data.spice.streaming = modeVal; } else if (virXMLNodeNameEqual(cur, "clipboard")) { - char *copypaste = virXMLPropString(cur, "copypaste"); int copypasteVal; + VIR_AUTOFREE(char *) copypaste = virXMLPropString(cur, "copypaste"); if (!copypaste) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -14239,15 +13991,13 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virTristateBoolTypeFromString(copypaste)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown copypaste value '%s'"), copypaste); - VIR_FREE(copypaste); goto error; } - VIR_FREE(copypaste); def->data.spice.copypaste = copypasteVal; } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - char *enable = virXMLPropString(cur, "enable"); int enableVal; + VIR_AUTOFREE(char *) enable = virXMLPropString(cur, "enable"); if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -14259,21 +14009,18 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virTristateBoolTypeFromString(enable)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - VIR_FREE(enable); goto error; } - VIR_FREE(enable); def->data.spice.filetransfer = enableVal; } else if (virXMLNodeNameEqual(cur, "gl")) { - char *enable = virXMLPropString(cur, "enable"); - char *rendernode = virXMLPropString(cur, "rendernode"); int enableVal; + VIR_AUTOFREE(char *) enable = virXMLPropString(cur, "enable"); + VIR_AUTOFREE(char *) rendernode = virXMLPropString(cur, "rendernode"); if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice gl element missing enable")); - VIR_FREE(rendernode); goto error; } @@ -14281,18 +14028,15 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virTristateBoolTypeFromString(enable)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - VIR_FREE(enable); - VIR_FREE(rendernode); goto error; } - VIR_FREE(enable); def->data.spice.gl = enableVal; VIR_STEAL_PTR(def->data.spice.rendernode, rendernode); } else if (virXMLNodeNameEqual(cur, "mouse")) { - char *mode = virXMLPropString(cur, "mode"); int modeVal; + VIR_AUTOFREE(char *) mode = virXMLPropString(cur, "mode"); if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -14304,10 +14048,8 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mouse mode value '%s'"), mode); - VIR_FREE(mode); goto error; } - VIR_FREE(mode); def->data.spice.mousemode = modeVal; } @@ -14317,10 +14059,6 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, ret = 0; error: - VIR_FREE(port); - VIR_FREE(tlsPort); - VIR_FREE(autoport); - VIR_FREE(defaultMode); return ret; } @@ -14369,8 +14107,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { virDomainGraphicsDefPtr def; - char *type = NULL; int typeVal; + VIR_AUTOFREE(char *) type = NULL; if (!(def = virDomainGraphicsDefNew(xmlopt))) return NULL; @@ -14419,8 +14157,6 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, } cleanup: - VIR_FREE(type); - return def; error: @@ -14433,8 +14169,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, static virDomainSoundCodecDefPtr virDomainSoundCodecDefParseXML(xmlNodePtr node) { - char *type; virDomainSoundCodecDefPtr def; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14447,8 +14183,6 @@ virDomainSoundCodecDefParseXML(xmlNodePtr node) } cleanup: - VIR_FREE(type); - return def; error: @@ -14464,9 +14198,9 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model; virDomainSoundDefPtr def; xmlNodePtr save = ctxt->node; + VIR_AUTOFREE(char *) model = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14483,7 +14217,7 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt, if (def->model == VIR_DOMAIN_SOUND_MODEL_ICH6 || def->model == VIR_DOMAIN_SOUND_MODEL_ICH9) { int ncodecs; - xmlNodePtr *codecNodes = NULL; + VIR_AUTOFREE(xmlNodePtr *) codecNodes = NULL; /* parse the <codec> subelements for sound models that support it */ ncodecs = virXPathNodeSet("./codec", ctxt, &codecNodes); @@ -14493,22 +14227,17 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt, if (ncodecs > 0) { size_t i; - if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) { - VIR_FREE(codecNodes); + if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) goto error; - } for (i = 0; i < ncodecs; i++) { virDomainSoundCodecDefPtr codec = virDomainSoundCodecDefParseXML(codecNodes[i]); - if (codec == NULL) { - VIR_FREE(codecNodes); + if (codec == NULL) goto error; - } codec->cad = def->ncodecs; /* that will do for now */ def->codecs[def->ncodecs++] = codec; } - VIR_FREE(codecNodes); } } @@ -14516,8 +14245,6 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(model); - ctxt->node = save; return def; @@ -14533,9 +14260,9 @@ virDomainWatchdogDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, unsigned int flags) { - char *model = NULL; - char *action = NULL; virDomainWatchdogDefPtr def; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) action = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14569,9 +14296,6 @@ virDomainWatchdogDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(action); - VIR_FREE(model); - return def; error: @@ -14587,13 +14311,13 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model = NULL; - char *backend = NULL; - char *type = NULL; virDomainRNGDefPtr def; xmlNodePtr save = ctxt->node; - xmlNodePtr *backends = NULL; int nbackends; + VIR_AUTOFREE(xmlNodePtr *) backends = NULL; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) backend = NULL; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14685,10 +14409,6 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(type); - VIR_FREE(backends); ctxt->node = save; return def; @@ -14705,11 +14425,11 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model; - char *deflate = NULL; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; unsigned int period = 0; + VIR_AUTOFREE(char *) model = NULL; + VIR_AUTOFREE(char *) deflate = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14756,9 +14476,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; cleanup: - VIR_FREE(model); - VIR_FREE(deflate); - ctxt->node = save; return def; @@ -14794,13 +14511,12 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *tmp = NULL; virDomainShmemDefPtr def = NULL; virDomainShmemDefPtr ret = NULL; xmlNodePtr msi = NULL; xmlNodePtr save = ctxt->node; xmlNodePtr server = NULL; - + VIR_AUTOFREE(char *) tmp = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -14864,7 +14580,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt, } def->msi.ioeventfd = val; } - VIR_FREE(tmp); } /* msi option is only relevant with a server */ @@ -14881,7 +14596,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_STEAL_PTR(ret, def); cleanup: ctxt->node = save; - VIR_FREE(tmp); virDomainShmemDefFree(def); return ret; } @@ -14953,7 +14667,7 @@ virSysinfoSystemParseXML(xmlNodePtr node, { int ret = -1; virSysinfoSystemDefPtr def; - char *tmpUUID = NULL; + VIR_AUTOFREE(char *) tmpUUID = NULL; if (!virXMLNodeNameEqual(node, "system")) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -15014,7 +14728,6 @@ virSysinfoSystemParseXML(xmlNodePtr node, ret = 0; cleanup: virSysinfoSystemDefFree(def); - VIR_FREE(tmpUUID); return ret; } @@ -15024,10 +14737,11 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, size_t *nbaseBoard) { int ret = -1; - virSysinfoBaseBoardDefPtr boards = NULL; size_t i, nboards = 0; - xmlNodePtr *nodes = NULL, oldnode = ctxt->node; + xmlNodePtr oldnode = ctxt->node; int n; + VIR_AUTOFREE(virSysinfoBaseBoardDefPtr) boards = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; if ((n = virXPathNodeSet("./baseBoard", ctxt, &nodes)) < 0) return ret; @@ -15065,8 +14779,6 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, *nbaseBoard = nboards; ret = 0; cleanup: - VIR_FREE(boards); - VIR_FREE(nodes); ctxt->node = oldnode; return ret; } @@ -15078,9 +14790,9 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt, { int ret = -1; virSysinfoOEMStringsDefPtr def; - xmlNodePtr *strings = NULL; int nstrings; size_t i; + VIR_AUTOFREE(xmlNodePtr *) strings = NULL; nstrings = virXPathNodeSet("./entry", ctxt, &strings); if (nstrings < 0) @@ -15101,7 +14813,6 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt, VIR_STEAL_PTR(*oem, def); ret = 0; cleanup: - VIR_FREE(strings); virSysinfoOEMStringsDefFree(def); return ret; } @@ -15157,7 +14868,7 @@ virSysinfoParseXML(xmlNodePtr node, { virSysinfoDefPtr def; xmlNodePtr oldnode, tmpnode; - char *type; + VIR_AUTOFREE(char *) type = NULL; if (!virXMLNodeNameEqual(node, "sysinfo")) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -15230,7 +14941,6 @@ virSysinfoParseXML(xmlNodePtr node, } cleanup: - VIR_FREE(type); return def; error: @@ -15324,9 +15034,9 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) { xmlNodePtr cur; virDomainVideoAccelDefPtr def; - char *accel2d = NULL; - char *accel3d = NULL; int val; + VIR_AUTOFREE(char *) accel2d = NULL; + VIR_AUTOFREE(char *) accel3d = NULL; cur = node->children; while (cur != NULL) { @@ -15365,8 +15075,6 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) } cleanup: - VIR_FREE(accel2d); - VIR_FREE(accel3d); return def; } @@ -15375,8 +15083,8 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node) { xmlNodePtr cur; virDomainVideoDriverDefPtr def; - char *vgaconf = NULL; int val; + VIR_AUTOFREE(char *) vgaconf = NULL; cur = node->children; while (cur != NULL) { @@ -15403,7 +15111,6 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node) def->vgaconf = val; cleanup: - VIR_FREE(vgaconf); return def; } @@ -15417,13 +15124,13 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, virDomainVideoDefPtr def; xmlNodePtr cur; xmlNodePtr saved = ctxt->node; - char *type = NULL; - char *heads = NULL; - char *vram = NULL; - char *vram64 = NULL; - char *ram = NULL; - char *vgamem = NULL; - char *primary = NULL; + VIR_AUTOFREE(char *) type = NULL; + VIR_AUTOFREE(char *) heads = NULL; + VIR_AUTOFREE(char *) vram = NULL; + VIR_AUTOFREE(char *) vram64 = NULL; + VIR_AUTOFREE(char *) ram = NULL; + VIR_AUTOFREE(char *) vgamem = NULL; + VIR_AUTOFREE(char *) primary = NULL; if (!(def = virDomainVideoDefNew())) return NULL; @@ -15530,14 +15237,6 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: ctxt->node = saved; - - VIR_FREE(type); - VIR_FREE(ram); - VIR_FREE(vram); - VIR_FREE(vram64); - VIR_FREE(vgamem); - VIR_FREE(heads); - return def; error: @@ -15554,8 +15253,8 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt, { virDomainHostdevDefPtr def; xmlNodePtr save = ctxt->node; - char *mode = virXMLPropString(node, "mode"); - char *type = virXMLPropString(node, "type"); + VIR_AUTOFREE(char *) mode = virXMLPropString(node, "mode"); + VIR_AUTOFREE(char *) type = virXMLPropString(node, "type"); ctxt->node = node; @@ -15614,8 +15313,6 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt, } cleanup: - VIR_FREE(type); - VIR_FREE(mode); ctxt->node = save; return def; @@ -15634,7 +15331,8 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt, { xmlNodePtr cur; virDomainRedirdevDefPtr def; - char *bus = NULL, *type = NULL; + VIR_AUTOFREE(char *) bus = NULL; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -15690,8 +15388,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: - VIR_FREE(bus); - VIR_FREE(type); return def; error: @@ -15741,10 +15437,12 @@ virDomainRedirFilterUSBVersionHelper(const char *version, static virDomainRedirFilterUSBDevDefPtr virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node) { - char *class; - char *vendor = NULL, *product = NULL; - char *version = NULL, *allow = NULL; virDomainRedirFilterUSBDevDefPtr def; + VIR_AUTOFREE(char *) class = NULL; + VIR_AUTOFREE(char *) vendor = NULL; + VIR_AUTOFREE(char *) product = NULL; + VIR_AUTOFREE(char *) version = NULL; + VIR_AUTOFREE(char *) allow = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -15816,11 +15514,6 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node) } cleanup: - VIR_FREE(class); - VIR_FREE(vendor); - VIR_FREE(product); - VIR_FREE(version); - VIR_FREE(allow); return def; error: @@ -15835,9 +15528,9 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, { int n; size_t i; - xmlNodePtr *nodes = NULL; xmlNodePtr save = ctxt->node; virDomainRedirFilterDefPtr def = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; if (VIR_ALLOC(def) < 0) goto error; @@ -15857,13 +15550,11 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, goto error; def->usbdevs[def->nusbdevs++] = usbdev; } - VIR_FREE(nodes); ctxt->node = save; return def; error: - VIR_FREE(nodes); virDomainRedirFilterDefFree(def); return NULL; } @@ -15876,7 +15567,8 @@ virDomainEventActionParseXML(xmlXPathContextPtr ctxt, int defaultVal, virEventActionFromStringFunc convFunc) { - char *tmp = virXPathString(xpath, ctxt); + VIR_AUTOFREE(char *) tmp = virXPathString(xpath, ctxt); + if (tmp == NULL) { *val = defaultVal; } else { @@ -15884,10 +15576,8 @@ virDomainEventActionParseXML(xmlXPathContextPtr ctxt, if (*val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown %s action: %s"), name, tmp); - VIR_FREE(tmp); return -1; } - VIR_FREE(tmp); } return 0; } @@ -15898,7 +15588,8 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, int *val) { int ret = -1; - char *tmp = virXPathString(xpath, ctxt); + VIR_AUTOFREE(char *) tmp = virXPathString(xpath, ctxt); + if (tmp) { *val = virTristateBoolTypeFromString(tmp); if (*val < 0) { @@ -15910,7 +15601,6 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, ret = 0; cleanup: - VIR_FREE(tmp); return ret; } @@ -15919,10 +15609,10 @@ static int virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, xmlNodePtr node) { - char *name = NULL; - char *enabled = NULL; int event; int ret = -1; + VIR_AUTOFREE(char *) name = NULL; + VIR_AUTOFREE(char *) enabled = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing perf event name")); @@ -15957,8 +15647,6 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, ret = 0; cleanup: - VIR_FREE(name); - VIR_FREE(enabled); return ret; } @@ -15968,8 +15656,8 @@ virDomainPerfDefParseXML(virDomainDefPtr def, { size_t i; int ret = -1; - xmlNodePtr *nodes = NULL; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; if ((n = virXPathNodeSet("./perf/event", ctxt, &nodes)) < 0) return n; @@ -15982,7 +15670,6 @@ virDomainPerfDefParseXML(virDomainDefPtr def, ret = 0; cleanup: - VIR_FREE(nodes); return ret; } @@ -15992,9 +15679,9 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, virDomainMemoryDefPtr def) { int ret = -1; - char *nodemask = NULL; xmlNodePtr save = ctxt->node; ctxt->node = node; + VIR_AUTOFREE(char *) nodemask = NULL; switch ((virDomainMemoryModel) def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: @@ -16039,7 +15726,6 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(nodemask); ctxt->node = save; return ret; } @@ -16102,10 +15788,10 @@ static virDomainSEVDefPtr virDomainSEVDefParseXML(xmlNodePtr sevNode, xmlXPathContextPtr ctxt) { - char *type = NULL; xmlNodePtr save = ctxt->node; virDomainSEVDefPtr def; unsigned long policy; + VIR_AUTOFREE(char *) type = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -16155,7 +15841,6 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, def->session = virXPathString("string(./session)", ctxt); cleanup: - VIR_FREE(type); ctxt->node = save; return def; @@ -16171,11 +15856,11 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *tmp = NULL; xmlNodePtr save = ctxt->node; xmlNodePtr node; virDomainMemoryDefPtr def; int val; + VIR_AUTOFREE(char *) tmp = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -16215,7 +15900,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt, def->discard = val; } - VIR_FREE(tmp); /* source */ if ((node = virXPathNode("./source", ctxt)) && @@ -16240,7 +15924,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt, return def; error: - VIR_FREE(tmp); virDomainMemoryDefFree(def); ctxt->node = save; return NULL; @@ -16251,11 +15934,12 @@ static virDomainIOMMUDefPtr virDomainIOMMUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { - virDomainIOMMUDefPtr iommu = NULL, ret = NULL; + virDomainIOMMUDefPtr ret = NULL; xmlNodePtr save = ctxt->node; xmlNodePtr driver; - char *tmp = NULL; int val; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(virDomainIOMMUDefPtr) iommu = NULL; ctxt->node = node; @@ -16316,8 +16000,6 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, cleanup: ctxt->node = save; - VIR_FREE(iommu); - VIR_FREE(tmp); return ret; } @@ -16328,11 +16010,12 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - virDomainVsockDefPtr vsock = NULL, ret = NULL; + virDomainVsockDefPtr ret = NULL; xmlNodePtr save = ctxt->node; xmlNodePtr cid; - char *tmp = NULL; int val; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(virDomainVsockDefPtr) vsock = NULL; ctxt->node = node; @@ -16381,8 +16064,6 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt, cleanup: ctxt->node = save; - VIR_FREE(vsock); - VIR_FREE(tmp); return ret; } @@ -17976,17 +17657,15 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps) { char *retemu; - virCapsDomainDataPtr capsdata; + VIR_AUTOFREE(virCapsDomainDataPtr) capsdata = NULL; if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, def->os.arch, def->virtType, NULL, NULL))) return NULL; - if (VIR_STRDUP(retemu, capsdata->emulator) < 0) { - VIR_FREE(capsdata); + if (VIR_STRDUP(retemu, capsdata->emulator) < 0) return NULL; - } - VIR_FREE(capsdata); + return retemu; } @@ -17994,12 +17673,12 @@ static int virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virDomainDefPtr def) { - xmlNodePtr *nodes = NULL; xmlNodePtr node; size_t i; int n; - char *tmp = NULL; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; /* analysis of the boot devices */ if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) @@ -18081,8 +17760,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, ret = 0; cleanup: - VIR_FREE(tmp); - VIR_FREE(nodes); return ret; } @@ -18163,7 +17840,7 @@ static virDomainIOThreadIDDefPtr virDomainIOThreadIDDefParseXML(xmlNodePtr node) { virDomainIOThreadIDDefPtr iothrid; - char *tmp = NULL; + VIR_AUTOFREE(char *) tmp = NULL; if (VIR_ALLOC(iothrid) < 0) return NULL; @@ -18181,7 +17858,6 @@ virDomainIOThreadIDDefParseXML(xmlNodePtr node) } cleanup: - VIR_FREE(tmp); return iothrid; error: @@ -18196,10 +17872,10 @@ virDomainDefParseIOThreads(virDomainDefPtr def, xmlXPathContextPtr ctxt) { size_t i; - char *tmp; int n = 0; unsigned int iothreads = 0; - xmlNodePtr *nodes = NULL; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; tmp = virXPathString("string(./iothreads[1])", ctxt); if (tmp && virStrToLong_uip(tmp, NULL, 10, &iothreads) < 0) { @@ -18207,7 +17883,6 @@ virDomainDefParseIOThreads(virDomainDefPtr def, _("invalid iothreads count '%s'"), tmp); goto error; } - VIR_FREE(tmp); /* Extract any iothread id's defined */ if ((n = virXPathNodeSet("./iothreadids/iothread", ctxt, &nodes)) < 0) @@ -18233,7 +17908,6 @@ virDomainDefParseIOThreads(virDomainDefPtr def, } def->iothreadids[def->niothreadids++] = iothrid; } - VIR_FREE(nodes); if (virDomainIOThreadIDDefArrayInit(def, iothreads) < 0) goto error; @@ -18241,7 +17915,6 @@ virDomainDefParseIOThreads(virDomainDefPtr def, return 0; error: - VIR_FREE(nodes); return -1; } @@ -18257,8 +17930,8 @@ virDomainVcpuPinDefParseXML(virDomainDefPtr def, { virDomainVcpuDefPtr vcpu; unsigned int vcpuid; - char *tmp = NULL; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; if (!(tmp = virXMLPropString(node, "vcpu"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu id in vcpupin")); @@ -18302,7 +17975,6 @@ virDomainVcpuPinDefParseXML(virDomainDefPtr def, ret = 0; cleanup: - VIR_FREE(tmp); return ret; } @@ -18318,7 +17990,7 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, int ret = -1; virDomainIOThreadIDDefPtr iothrid; unsigned int iothreadid; - char *tmp = NULL; + VIR_AUTOFREE(char *) tmp = NULL; VIR_AUTOPTR(virBitmap) cpumask = NULL; if (!(tmp = virXMLPropString(node, "iothread"))) { @@ -18374,7 +18046,6 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(tmp); return ret; } @@ -18387,7 +18058,7 @@ static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { virBitmapPtr ret = NULL; - char *tmp = NULL; + VIR_AUTOFREE(char *) tmp = NULL; VIR_AUTOPTR(virBitmap) def = NULL; if (!(tmp = virXMLPropString(node, "cpuset"))) { @@ -18408,7 +18079,6 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) VIR_STEAL_PTR(ret, def); cleanup: - VIR_FREE(tmp); return ret; } @@ -18544,7 +18214,7 @@ virDomainHugepagesParseXML(xmlNodePtr node, { int ret = -1; xmlNodePtr oldnode = ctxt->node; - char *nodeset = NULL; + VIR_AUTOFREE(char *) nodeset = NULL; ctxt->node = node; @@ -18572,7 +18242,6 @@ virDomainHugepagesParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(nodeset); ctxt->node = oldnode; return ret; } @@ -18649,9 +18318,9 @@ virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader) { int ret = -1; - char *readonly_str = NULL; - char *secure_str = NULL; - char *type_str = NULL; + VIR_AUTOFREE(char *) readonly_str = NULL; + VIR_AUTOFREE(char *) secure_str = NULL; + VIR_AUTOFREE(char *) type_str = NULL; readonly_str = virXMLPropString(node, "readonly"); secure_str = virXMLPropString(node, "secure"); @@ -18684,9 +18353,6 @@ virDomainLoaderDefParseXML(xmlNodePtr node, ret = 0; cleanup: - VIR_FREE(readonly_str); - VIR_FREE(secure_str); - VIR_FREE(type_str); return ret; } @@ -18698,8 +18364,8 @@ virDomainSchedulerParse(xmlNodePtr node, int *priority) { virBitmapPtr ret = NULL; - char *tmp = NULL; int pol = 0; + VIR_AUTOFREE(char *) tmp = NULL; if (!(tmp = virXMLPropString(node, name))) { virReportError(VIR_ERR_XML_ERROR, @@ -18748,13 +18414,11 @@ virDomainSchedulerParse(xmlNodePtr node, _("Invalid value for element priority")); goto error; } - VIR_FREE(tmp); } return ret; error: - VIR_FREE(tmp); virBitmapFree(ret); return NULL; } @@ -18837,13 +18501,13 @@ virDomainVcpuParse(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt) { int n; - xmlNodePtr *nodes = NULL; xmlNodePtr vcpuNode; size_t i; - char *tmp = NULL; unsigned int maxvcpus; unsigned int vcpus; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; vcpus = maxvcpus = 1; @@ -18977,9 +18641,6 @@ virDomainVcpuParse(virDomainDefPtr def, ret = 0; cleanup: - VIR_FREE(nodes); - VIR_FREE(tmp); - return ret; } @@ -18988,12 +18649,12 @@ static int virDomainDefParseBootOptions(virDomainDefPtr def, xmlXPathContextPtr ctxt) { - xmlNodePtr *nodes = NULL; - char *tmp = NULL; char *name = NULL; int ret = -1; size_t i; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; + VIR_AUTOFREE(char *) tmp = NULL; /* * Booting options for different OS types.... @@ -19124,8 +18785,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, ret = 0; error: - VIR_FREE(nodes); - VIR_FREE(tmp); return ret; } @@ -19135,8 +18794,8 @@ virDomainResctrlParseVcpus(virDomainDefPtr def, xmlNodePtr node, virBitmapPtr *vcpus) { - char *vcpus_str = NULL; int ret = -1; + VIR_AUTOFREE(char *) vcpus_str = NULL; vcpus_str = virXMLPropString(node, "vcpus"); if (!vcpus_str) { @@ -19157,7 +18816,6 @@ virDomainResctrlParseVcpus(virDomainDefPtr def, ret = 0; cleanup: - VIR_FREE(vcpus_str); return ret; } @@ -19197,8 +18855,8 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, unsigned int cache; int type; unsigned long long size; - char *tmp = NULL; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; ctxt->node = node; @@ -19243,7 +18901,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, tmp); goto cleanup; } - VIR_FREE(tmp); if (virDomainParseScaledValue("./@size", "./@unit", ctxt, &size, 1024, @@ -19256,7 +18913,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt, ret = 0; cleanup: ctxt->node = oldnode; - VIR_FREE(tmp); return ret; } @@ -19329,14 +18985,14 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, { virDomainResctrlMonDefPtr domresmon = NULL; xmlNodePtr oldnode = ctxt->node; - xmlNodePtr *nodes = NULL; unsigned int level = 0; - char *tmp = NULL; - char *id = NULL; size_t i = 0; int n = 0; int rv = -1; int ret = -1; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(char *) id = NULL; ctxt->node = node; @@ -19424,9 +19080,6 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, ret = 0; cleanup: ctxt->node = oldnode; - VIR_FREE(id); - VIR_FREE(tmp); - VIR_FREE(nodes); virDomainResctrlMonDefFree(domresmon); return ret; } @@ -19438,10 +19091,10 @@ virDomainResctrlNew(xmlNodePtr node, virBitmapPtr vcpus, unsigned int flags) { - char *vcpus_str = NULL; - char *alloc_id = NULL; virDomainResctrlDefPtr resctrl = NULL; virDomainResctrlDefPtr ret = NULL; + VIR_AUTOFREE(char *) vcpus_str = NULL; + VIR_AUTOFREE(char *) alloc_id = NULL; /* We need to format it back because we need to be consistent in the naming * even when users specify some "sub-optimal" string there. */ @@ -19479,8 +19132,6 @@ virDomainResctrlNew(xmlNodePtr node, VIR_STEAL_PTR(ret, resctrl); cleanup: virDomainResctrlDefFree(resctrl); - VIR_FREE(alloc_id); - VIR_FREE(vcpus_str); return ret; } @@ -19492,13 +19143,13 @@ virDomainCachetuneDefParse(virDomainDefPtr def, unsigned int flags) { xmlNodePtr oldnode = ctxt->node; - xmlNodePtr *nodes = NULL; virResctrlAllocPtr alloc = NULL; virDomainResctrlDefPtr resctrl = NULL; ssize_t i = 0; int n; int ret = -1; VIR_AUTOPTR(virBitmap) vcpus = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; ctxt->node = node; @@ -19558,7 +19209,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, ctxt->node = oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - VIR_FREE(nodes); return ret; } @@ -19570,10 +19220,10 @@ virDomainDefParseCaps(virDomainDefPtr def, unsigned int flags) { int ret = -1; - char *virttype = NULL; - char *arch = NULL; - char *ostype = NULL; - virCapsDomainDataPtr capsdata = NULL; + VIR_AUTOFREE(char *) virttype = NULL; + VIR_AUTOFREE(char *) arch = NULL; + VIR_AUTOFREE(char *) ostype = NULL; + VIR_AUTOFREE(virCapsDomainDataPtr) capsdata = NULL; virttype = virXPathString("string(./@type)", ctxt); ostype = virXPathString("string(./os/type[1])", ctxt); @@ -19644,10 +19294,6 @@ virDomainDefParseCaps(virDomainDefPtr def, ret = 0; cleanup: - VIR_FREE(virttype); - VIR_FREE(ostype); - VIR_FREE(arch); - VIR_FREE(capsdata); return ret; } @@ -19660,8 +19306,8 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt, xmlNodePtr oldnode = ctxt->node; unsigned int id; unsigned int bandwidth; - char *tmp = NULL; int ret = -1; + VIR_AUTOFREE(char *) tmp = NULL; ctxt->node = node; @@ -19691,14 +19337,12 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt, tmp); goto cleanup; } - VIR_FREE(tmp); if (virResctrlAllocSetMemoryBandwidth(alloc, id, bandwidth) < 0) goto cleanup; ret = 0; cleanup: ctxt->node = oldnode; - VIR_FREE(tmp); return ret; } @@ -19710,10 +19354,10 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, unsigned int flags) { xmlNodePtr oldnode = ctxt->node; - xmlNodePtr *nodes = NULL; virResctrlAllocPtr alloc = NULL; virDomainResctrlDefPtr resctrl = NULL; VIR_AUTOPTR(virBitmap) vcpus = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; ssize_t i = 0; int n; @@ -19772,7 +19416,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ctxt->node = oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - VIR_FREE(nodes); return ret; } @@ -19785,8 +19428,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - xmlNodePtr *nodes = NULL, node = NULL; - char *tmp = NULL; + xmlNodePtr node = NULL; size_t i, j; int n, gic_version; long id = -1; @@ -19796,18 +19438,19 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_other = false; bool usb_master = false; char *netprefix = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; + VIR_AUTOFREE(char *) tmp = NULL; if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - char *schema = virFileFindResource("domain.rng", - abs_topsrcdir "/docs/schemas", - PKGDATADIR "/schemas"); + VIR_AUTOFREE(char *) schema = NULL; + + schema = virFileFindResource("domain.rng", + abs_topsrcdir "/docs/schemas", + PKGDATADIR "/schemas"); if (!schema) return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) { - VIR_FREE(schema); + if (virXMLValidateAgainstSchema(schema, xml) < 0) return NULL; - } - VIR_FREE(schema); } if (!(def = virDomainDefNew())) @@ -21433,7 +21076,6 @@ virDomainDefParseXML(xmlDocPtr xml, def->idmap.ngidmap = n; } - VIR_FREE(nodes); if ((def->idmap.uidmap && !def->idmap.gidmap) || (!def->idmap.uidmap && def->idmap.gidmap)) { @@ -21462,7 +21104,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } def->os.smbios_mode = mode; - VIR_FREE(tmp); } if (virDomainKeyWrapDefParseXML(def, ctxt) < 0) @@ -21484,8 +21125,6 @@ virDomainDefParseXML(xmlDocPtr xml, return def; error: - VIR_FREE(tmp); - VIR_FREE(nodes); virDomainDefFree(def); return NULL; } @@ -21498,17 +21137,17 @@ virDomainObjParseXML(xmlDocPtr xml, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - char *tmp = NULL; long val; xmlNodePtr config; xmlNodePtr oldnode; virDomainObjPtr obj; - xmlNodePtr *nodes = NULL; size_t i; int n; int state; int reason = 0; void *parseOpaque = NULL; + VIR_AUTOFREE(char *) tmp = NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; if (!(obj = virDomainObjNew(xmlopt))) return NULL; @@ -21534,7 +21173,6 @@ virDomainObjParseXML(xmlDocPtr xml, if ((state = virDomainStateTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain state '%s'"), tmp); - VIR_FREE(tmp); goto error; } VIR_FREE(tmp); @@ -21543,10 +21181,8 @@ virDomainObjParseXML(xmlDocPtr xml, if ((reason = virDomainStateReasonFromString(state, tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain state reason '%s'"), tmp); - VIR_FREE(tmp); goto error; } - VIR_FREE(tmp); } virDomainObjSetState(obj, state, reason); @@ -21574,7 +21210,6 @@ virDomainObjParseXML(xmlDocPtr xml, virDomainObjTaint(obj, flag); } } - VIR_FREE(nodes); if (xmlopt->privateData.parse && xmlopt->privateData.parse(ctxt, obj, &xmlopt->config) < 0) @@ -21595,7 +21230,6 @@ virDomainObjParseXML(xmlDocPtr xml, error: virObjectUnref(obj); - VIR_FREE(nodes); return NULL; } @@ -23129,8 +22763,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src, { size_t i; virErrorPtr err; - char *strSrc; - char *strDst; + VIR_AUTOFREE(char *) strSrc = NULL; + VIR_AUTOFREE(char *) strDst = NULL; if (src->virtType != dst->virtType) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -23599,8 +23233,6 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src, strDst = virDomainDefFormat(dst, NULL, 0); VIR_DEBUG("XMLs that failed stability check were: src=\"%s\", dst=\"%s\"", NULLSTR(strSrc), NULLSTR(strDst)); - VIR_FREE(strSrc); - VIR_FREE(strDst); if (err) { virSetError(err); @@ -24060,7 +23692,7 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf, unsigned int flags) { size_t n; - char *path = NULL; + VIR_AUTOFREE(char *) path = NULL; virBufferAsprintf(attrBuf, " protocol='%s'", virStorageNetProtocolTypeToString(src->protocol)); @@ -24072,8 +23704,6 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf, virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path); - VIR_FREE(path); - if (src->haveTLS != VIR_TRISTATE_BOOL_ABSENT && !(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && src->tlsFromConfig)) @@ -26508,8 +26138,8 @@ static int virDomainMemorySourceDefFormat(virBufferPtr buf, virDomainMemoryDefPtr def) { - char *bitmap = NULL; int ret = -1; + VIR_AUTOFREE(char *) bitmap = NULL; if (!def->pagesize && !def->sourceNodes && !def->nvdimmPath) return 0; @@ -26553,7 +26183,6 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, ret = 0; cleanup: - VIR_FREE(bitmap); return ret; } @@ -27704,7 +27333,7 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDefPtr domresmon, virResctrlMonitorType tag, virBufferPtr buf) { - char *vcpus = NULL; + VIR_AUTOFREE(char *) vcpus = NULL; if (domresmon->tag != tag) return 0; @@ -27722,7 +27351,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDefPtr domresmon, virBufferAsprintf(buf, "vcpus='%s'/>\n", vcpus); - VIR_FREE(vcpus); return 0; } @@ -27733,9 +27361,9 @@ virDomainCachetuneDefFormat(virBufferPtr buf, unsigned int flags) { virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; - char *vcpus = NULL; size_t i = 0; int ret = -1; + VIR_AUTOFREE(char *) vcpus = NULL; virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachCache(resctrl->alloc, @@ -27779,7 +27407,6 @@ virDomainCachetuneDefFormat(virBufferPtr buf, ret = 0; cleanup: virBufferFreeAndReset(&childrenBuf); - VIR_FREE(vcpus); return ret; } @@ -27804,8 +27431,8 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, unsigned int flags) { virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; - char *vcpus = NULL; int ret = -1; + VIR_AUTOFREE(char *) vcpus = NULL; virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachMemory(resctrl->alloc, @@ -27842,7 +27469,6 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, ret = 0; cleanup: virBufferFreeAndReset(&childrenBuf); - VIR_FREE(vcpus); return ret; } @@ -27977,8 +27603,8 @@ virDomainCpuDefFormat(virBufferPtr buf, { virDomainVcpuDefPtr vcpu; size_t i; - char *cpumask = NULL; int ret = -1; + VIR_AUTOFREE(char *) cpumask = NULL; virBufferAddLit(buf, "<vcpu"); virBufferAsprintf(buf, " placement='%s'", @@ -28017,8 +27643,6 @@ virDomainCpuDefFormat(virBufferPtr buf, ret = 0; cleanup: - VIR_FREE(cpumask); - return ret; } @@ -29215,8 +28839,8 @@ virDomainSaveXML(const char *configDir, const char *xml) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile = NULL; int ret = -1; + VIR_AUTOFREE(char *) configFile = NULL; if (!configDir) return 0; @@ -29237,7 +28861,6 @@ virDomainSaveXML(const char *configDir, xml); cleanup: - VIR_FREE(configFile); return ret; } @@ -29247,7 +28870,7 @@ virDomainSaveConfig(const char *configDir, virDomainDefPtr def) { int ret = -1; - char *xml; + VIR_AUTOFREE(char *) xml = NULL; if (!(xml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; @@ -29257,7 +28880,6 @@ virDomainSaveConfig(const char *configDir, ret = 0; cleanup: - VIR_FREE(xml); return ret; } @@ -29274,7 +28896,7 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST); int ret = -1; - char *xml; + VIR_AUTOFREE(char *) xml = NULL; if (!(xml = virDomainObjFormat(xmlopt, obj, caps, flags))) goto cleanup; @@ -29284,7 +28906,6 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, ret = 0; cleanup: - VIR_FREE(xml); return ret; } @@ -29294,8 +28915,9 @@ virDomainDeleteConfig(const char *configDir, const char *autostartDir, virDomainObjPtr dom) { - char *configFile = NULL, *autostartLink = NULL; int ret = -1; + VIR_AUTOFREE(char *) configFile = NULL; + VIR_AUTOFREE(char *) autostartLink = NULL; if ((configFile = virDomainConfigFile(configDir, dom->def->name)) == NULL) goto cleanup; @@ -29318,8 +28940,6 @@ virDomainDeleteConfig(const char *configDir, ret = 0; cleanup: - VIR_FREE(configFile); - VIR_FREE(autostartLink); return ret; } @@ -29585,7 +29205,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, int ret = -1; size_t depth = 0; virStorageSourcePtr tmp; - char *brokenRaw = NULL; + VIR_AUTOFREE(char *) brokenRaw = NULL; if (!ignoreOpenFailure) { if (virStorageFileChainGetBroken(disk->src, &brokenRaw) < 0) @@ -29613,7 +29233,6 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, ret = 0; cleanup: - VIR_FREE(brokenRaw); return ret; } @@ -29629,11 +29248,11 @@ virDomainDefCopy(virDomainDefPtr src, void *parseOpaque, bool migratable) { - char *xml; virDomainDefPtr ret; unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + VIR_AUTOFREE(char *) xml = NULL; if (migratable) format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; @@ -29644,7 +29263,6 @@ virDomainDefCopy(virDomainDefPtr src, ret = virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); - VIR_FREE(xml); return ret; } @@ -30072,9 +29690,9 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, virDomainDeviceDefPtr ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; int flags = VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_SECURE; - char *xmlStr = NULL; int rc = -1; char *netprefix; + VIR_AUTOFREE(char *) xmlStr = NULL; switch ((virDomainDeviceType) src->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -30161,7 +29779,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); cleanup: - VIR_FREE(xmlStr); return ret; } @@ -30492,8 +30109,8 @@ virDomainDefGetShortName(const virDomainDef *def) { wchar_t wshortname[VIR_DOMAIN_SHORT_NAME_MAX + 1] = {0}; size_t len = 0; - char *shortname = NULL; char *ret = NULL; + VIR_AUTOFREE(char *) shortname = NULL; /* No need to do the whole conversion thing when there are no multibyte * characters. The same applies for illegal sequences as they can occur @@ -30540,7 +30157,6 @@ virDomainDefGetShortName(const virDomainDef *def) ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname)); cleanup: - VIR_FREE(shortname); return ret; } @@ -30819,9 +30435,9 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface) { virConnectPtr conn = NULL; virNetworkPtr net = NULL; - char *xml = NULL; virNetworkDefPtr def = NULL; int ret = -1; + VIR_AUTOFREE(char *) xml = NULL; if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) return iface->type; @@ -30888,7 +30504,6 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface) cleanup: virNetworkDefFree(def); - VIR_FREE(xml); virObjectUnref(conn); virObjectUnref(net); return ret; @@ -31017,10 +30632,10 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def) virConnectPtr conn = NULL; virStoragePoolPtr pool = NULL; virStorageVolPtr vol = NULL; - char *poolxml = NULL; virStorageVolInfo info; int ret = -1; VIR_AUTOPTR(virStoragePoolDef) pooldef = NULL; + VIR_AUTOFREE(char *) poolxml = NULL; if (def->src->type != VIR_STORAGE_TYPE_VOLUME) return 0; @@ -31178,7 +30793,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def) virObjectUnref(conn); virObjectUnref(pool); virObjectUnref(vol); - VIR_FREE(poolxml); return ret; } -- 2.20.1

On Wed, Feb 20, 2019 at 01:34:03PM -0500, John Ferlan wrote:
Let's make use of the auto __cleanup capabilities for VIR_FREE consumers. In some cases adding or removing blank lines for readability.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- Nicely done.
Reviewed-by: Erik Skultety <eskultet@redhat.com>

Now that we're using VIR_AUTOFREE there's quite a bit of clean up possible for now unnecessary goto paths. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/domain_conf.c | 801 ++++++++++++++++------------------------- 1 file changed, 310 insertions(+), 491 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 98a35b0296..0a28ee3dd8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1101,32 +1101,31 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, { int state_type; int name_type; - int ret = -1; VIR_AUTOFREE(char *) name = NULL; VIR_AUTOFREE(char *) state = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", _("missing name for cipher")); - goto cleanup; + return -1; } if ((name_type = virDomainKeyWrapCipherNameTypeFromString(name)) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s is not a supported cipher name"), name); - goto cleanup; + return -1; } if (!(state = virXMLPropString(node, "state"))) { virReportError(VIR_ERR_CONF_SYNTAX, _("missing state for cipher named %s"), name); - goto cleanup; + return -1; } if ((state_type = virTristateSwitchTypeFromString(state)) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s is not a supported cipher state"), state); - goto cleanup; + return -1; } switch ((virDomainKeyWrapCipherName) name_type) { @@ -1137,7 +1136,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, "one cipher node with name %s"), virDomainKeyWrapCipherNameTypeToString(name_type)); - goto cleanup; + return -1; } keywrap->aes = state_type; break; @@ -1149,7 +1148,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, "one cipher node with name %s"), virDomainKeyWrapCipherNameTypeToString(name_type)); - goto cleanup; + return -1; } keywrap->dea = state_type; break; @@ -1158,10 +1157,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, break; } - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -1264,7 +1260,6 @@ static int virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { - int ret = -1; int val; virDomainVirtioOptionsPtr res; VIR_AUTOFREE(char *) str = NULL; @@ -1281,7 +1276,7 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, if ((val = virTristateSwitchTypeFromString(str)) <= 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid iommu value")); - goto cleanup; + return -1; } res->iommu = val; } @@ -1291,15 +1286,12 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, if ((val = virTristateSwitchTypeFromString(str)) <= 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid ats value")); - goto cleanup; + return -1; } res->ats = val; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -5333,7 +5325,6 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, void *data) { virHashTablePtr bootHash = data; - int ret = -1; VIR_AUTOFREE(char *) order = NULL; if (info->bootIndex == 0) @@ -5348,22 +5339,19 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED, return 0; } if (virAsprintf(&order, "%u", info->bootIndex) < 0) - goto cleanup; + return -1; if (virHashLookup(bootHash, order)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("boot order '%s' used for more than one device"), order); - goto cleanup; + return -1; } if (virHashAddEntry(bootHash, order, (void *) 1) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - return ret; + return 0; } @@ -6883,7 +6871,6 @@ static int virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virDomainDeviceUSBMasterPtr master) { - int ret = -1; VIR_AUTOFREE(char *) startport = NULL; memset(master, 0, sizeof(*master)); @@ -6894,27 +6881,23 @@ virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virStrToLong_ui(startport, NULL, 10, &master->startport) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse <master> 'startport' attribute")); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int virDomainDeviceBootParseXML(xmlNodePtr node, virDomainDeviceInfoPtr info) { - int ret = -1; VIR_AUTOFREE(char *) order = NULL; VIR_AUTOFREE(char *) loadparm = NULL; if (!(order = virXMLPropString(node, "order"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing boot order attribute")); - goto cleanup; + return -1; } if (virStrToLong_uip(order, NULL, 10, &info->bootIndex) < 0 || @@ -6922,7 +6905,7 @@ virDomainDeviceBootParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("incorrect boot order '%s', expecting positive integer"), order); - goto cleanup; + return -1; } loadparm = virXMLPropString(node, "loadparm"); @@ -6931,26 +6914,22 @@ virDomainDeviceBootParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to convert loadparm '%s' to upper case"), loadparm); - goto cleanup; + return -1; } if (!virDomainDeviceLoadparmIsValid(info->loadparm)) { VIR_FREE(info->loadparm); - goto cleanup; + return -1; } } - ret = 0; - - cleanup: - return ret; + return 0; } static int virDomainDeviceISAAddressParseXML(xmlNodePtr node, virDomainDeviceISAAddressPtr addr) { - int ret = -1; VIR_AUTOFREE(char *) iobase = NULL; VIR_AUTOFREE(char *) irq = NULL; @@ -6963,19 +6942,17 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node, virStrToLong_uip(iobase, NULL, 16, &addr->iobase) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse <address> 'iobase' attribute")); - goto cleanup; + return -1; } if (irq && virStrToLong_uip(irq, NULL, 16, &addr->irq) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse <address> 'irq' attribute")); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -6983,7 +6960,6 @@ static int virDomainDeviceDimmAddressParseXML(xmlNodePtr node, virDomainDeviceDimmAddressPtr addr) { - int ret = -1; VIR_AUTOFREE(char *) tmp = NULL; if (!(tmp = virXMLPropString(node, "slot")) || @@ -6991,7 +6967,7 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("invalid or missing dimm slot id '%s'"), NULLSTR(tmp)); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -6999,14 +6975,11 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, if (virStrToLong_ullp(tmp, NULL, 16, &addr->base) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid dimm base address '%s'"), tmp); - goto cleanup; + return -1; } } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -7014,57 +6987,56 @@ static int virDomainDeviceAddressParseXML(xmlNodePtr address, virDomainDeviceInfoPtr info) { - int ret = -1; VIR_AUTOFREE(char *) type = virXMLPropString(address, "type"); if (type) { if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown address type '%s'"), type); - goto cleanup; + return -1; } } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No type specified for device address")); - goto cleanup; + return -1; } switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: if (virDomainDeviceDriveAddressParseXML(address, &info->addr.drive) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: if (virDomainDeviceVirtioSerialAddressParseXML (address, &info->addr.vioserial) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: if (virDomainDeviceCcidAddressParseXML(address, &info->addr.ccid) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: if (virDomainDeviceUSBAddressParseXML(address, &info->addr.usb) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: if (virDomainDeviceSpaprVioAddressParseXML(address, &info->addr.spaprvio) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: if (virDomainDeviceCCWAddressParseXML (address, &info->addr.ccw) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: @@ -7072,17 +7044,17 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: if (virDomainDeviceISAAddressParseXML(address, &info->addr.isa) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: virReportError(VIR_ERR_XML_ERROR, "%s", _("virtio-s390 bus doesn't have an address")); - goto cleanup; + return -1; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: if (virDomainDeviceDimmAddressParseXML(address, &info->addr.dimm) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: @@ -7090,9 +7062,7 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, break; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -7534,7 +7504,6 @@ static int virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr scsisrc) { - int ret = -1; bool got_address = false, got_adapter = false; xmlNodePtr cur; virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; @@ -7550,7 +7519,7 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("more than one source addresses is " "specified for scsi hostdev")); - goto cleanup; + return -1; } if (!(bus = virXMLPropString(cur, "bus")) || @@ -7559,26 +7528,26 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("'bus', 'target', and 'unit' must be specified " "for scsi hostdev source address")); - goto cleanup; + return -1; } if (virStrToLong_uip(bus, NULL, 0, &scsihostsrc->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse bus '%s'"), bus); - goto cleanup; + return -1; } if (virStrToLong_uip(target, NULL, 0, &scsihostsrc->target) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse target '%s'"), target); - goto cleanup; + return -1; } if (virStrToLong_ullp(unit, NULL, 0, &scsihostsrc->unit) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse unit '%s'"), unit); - goto cleanup; + return -1; } got_address = true; @@ -7587,12 +7556,12 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("more than one adapters is specified " "for scsi hostdev source")); - goto cleanup; + return -1; } if (!(scsihostsrc->adapter = virXMLPropString(cur, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("'adapter' must be specified for scsi hostdev source")); - goto cleanup; + return -1; } got_adapter = true; @@ -7600,7 +7569,7 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, _("unsupported element '%s' of scsi hostdev source"), cur->name); - goto cleanup; + return -1; } } cur = cur->next; @@ -7610,12 +7579,10 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("'adapter' and 'address' must be specified for scsi " "hostdev source")); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -7694,7 +7661,6 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr scsisrc, xmlXPathContextPtr ctxt) { - int ret = -1; VIR_AUTOFREE(char *) protocol = NULL; if ((protocol = virXMLPropString(sourcenode, "protocol"))) { @@ -7704,17 +7670,14 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown SCSI subsystem protocol '%s'"), protocol); - goto cleanup; + return -1; } } if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) - ret = virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt); - else - ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc); + return virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt); - cleanup: - return ret; + return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc); } static int @@ -7722,14 +7685,13 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevDefPtr def) { virDomainHostdevSubsysSCSIVHostPtr hostsrc = &def->source.subsys.u.scsi_host; - int ret = -1; VIR_AUTOFREE(char *) protocol = NULL; VIR_AUTOFREE(char *) wwpn = NULL; if (!(protocol = virXMLPropString(sourcenode, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing scsi_host subsystem protocol")); - return ret; + return -1; } if ((hostsrc->protocol = @@ -7737,7 +7699,7 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown scsi_host subsystem protocol '%s'"), protocol); - goto cleanup; + return -1; } switch ((virDomainHostdevSubsysSCSIHostProtocolType) hostsrc->protocol) { @@ -7745,13 +7707,13 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, if (!(wwpn = virXMLPropString(sourcenode, "wwpn"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vhost-scsi hostdev source wwpn")); - goto cleanup; + return -1; } if (!STRPREFIX(wwpn, "naa.") || !virValidateWWN(wwpn + 4)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed 'wwpn' value")); - goto cleanup; + return -1; } VIR_STEAL_PTR(hostsrc->wwpn, wwpn); break; @@ -7760,20 +7722,17 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virReportError(VIR_ERR_XML_ERROR, _("Invalid hostdev protocol '%s'"), virDomainHostdevSubsysSCSIHostProtocolTypeToString(hostsrc->protocol)); - goto cleanup; + return -1; break; } - ret = 0; - cleanup: - return ret; + return 0; } static int virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def, xmlXPathContextPtr ctxt) { - int ret = -1; unsigned char uuid[VIR_UUID_BUFLEN] = {0}; xmlNodePtr node = NULL; virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev; @@ -7782,26 +7741,24 @@ virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def, if (!(node = virXPathNode("./source/address", ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Missing <address> element")); - goto cleanup; + return -1; } if (!(uuidxml = virXMLPropString(node, "uuid"))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Missing 'uuid' attribute for element <address>")); - goto cleanup; + return -1; } if (virUUIDParse(uuidxml, uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse uuid attribute of element <address>")); - goto cleanup; + return -1; } virUUIDFormat(uuid, mdevsrc->uuidstr); - ret = 0; - cleanup: - return ret; + return 0; } static int @@ -7813,7 +7770,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, { xmlNodePtr sourcenode; int backend; - int ret = -1; virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi; virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev; @@ -7853,18 +7809,18 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown host device source address type '%s'"), type); - goto cleanup; + return -1; } } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing source address type")); - goto cleanup; + return -1; } if (!(sourcenode = virXPathNode("./source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing <source> element in hostdev device")); - goto cleanup; + return -1; } if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && @@ -7872,20 +7828,20 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Setting startupPolicy is only allowed for USB" " devices")); - goto cleanup; + return -1; } if (sgio) { if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("sgio is only supported for scsi host device")); - goto cleanup; + return -1; } if ((scsisrc->sgio = virDomainDeviceSGIOTypeFromString(sgio)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown sgio mode '%s'"), sgio); - goto cleanup; + return -1; } } @@ -7893,14 +7849,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("rawio is only supported for scsi host device")); - goto cleanup; + return -1; } if ((scsisrc->rawio = virTristateBoolTypeFromString(rawio)) <= 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown hostdev rawio setting '%s'"), rawio); - goto cleanup; + return -1; } } @@ -7909,21 +7865,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, "%s", _("'model' attribute in <hostdev> is only supported " "when type='mdev'")); - goto cleanup; + return -1; } } else { if (!model) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'model' attribute in mediated device's " "<hostdev> element")); - goto cleanup; + return -1; } if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown hostdev model '%s'"), model); - goto cleanup; + return -1; } if (display && @@ -7932,14 +7888,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, _("unknown value '%s' for <hostdev> attribute " "'display'"), display); - goto cleanup; + return -1; } } switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) < 0) - goto cleanup; + return -1; backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; if ((backendStr = virXPathString("string(./driver/@name)", ctxt)) && @@ -7948,7 +7904,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown PCI device <driver name='%s'/> " "has been specified"), backendStr); - goto cleanup; + return -1; } pcisrc->backend = backend; @@ -7956,33 +7912,31 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: if (virDomainHostdevSubsysUSBDefParseXML(sourcenode, def) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctxt) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0) - goto cleanup; + return -1; break; default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("address type='%s' not supported in hostdev interfaces"), virDomainHostdevSubsysTypeToString(def->source.subsys.type)); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } static virNetDevIPAddrPtr @@ -8001,7 +7955,7 @@ virDomainNetIPParseXML(xmlNodePtr node) if (!(address = virXMLPropString(node, "address"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing required address in <ip>")); - goto cleanup; + return NULL; } familyStr = virXMLPropString(node, "family"); @@ -8013,13 +7967,13 @@ virDomainNetIPParseXML(xmlNodePtr node) family = virSocketAddrNumericFamily(address); if (VIR_ALLOC(ip) < 0) - goto cleanup; + return NULL; if (virSocketAddrParse(&ip->address, address, family) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid address '%s' in <ip>"), address); - goto cleanup; + return NULL; } prefixStr = virXMLPropString(node, "prefix"); @@ -8030,7 +7984,7 @@ virDomainNetIPParseXML(xmlNodePtr node) virReportError(VIR_ERR_XML_ERROR, _("Invalid prefix value '%s' in <ip>"), prefixStr); - goto cleanup; + return NULL; } ip->prefix = prefixValue; @@ -8038,12 +7992,10 @@ virDomainNetIPParseXML(xmlNodePtr node) virSocketAddrParse(&ip->peer, peer, family) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Invalid peer '%s' in <ip>"), peer); - goto cleanup; + return NULL; } VIR_STEAL_PTR(ret, ip); - - cleanup: return ret; } @@ -8842,7 +8794,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, unsigned int flags) { int tlsCfgVal; - int ret = -1; VIR_AUTOFREE(char *) protocol = NULL; VIR_AUTOFREE(char *) haveTLS = NULL; VIR_AUTOFREE(char *) tlsCfg = NULL; @@ -8850,27 +8801,27 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, if (!(protocol = virXMLPropString(node, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing network source protocol type")); - goto cleanup; + return -1; } if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol type '%s'"), protocol); - goto cleanup; + return -1; } if (!(src->path = virXMLPropString(node, "name")) && src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for disk source")); - goto cleanup; + return -1; } if ((haveTLS = virXMLPropString(node, "tls")) && (src->haveTLS = virTristateBoolTypeFromString(haveTLS)) <= 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown disk source 'tls' setting '%s'"), haveTLS); - goto cleanup; + return -1; } if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && @@ -8879,7 +8830,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("Invalid tlsFromConfig value: %s"), tlsCfg); - goto cleanup; + return -1; } src->tlsFromConfig = !!tlsCfgVal; } @@ -8895,13 +8846,13 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("can't split path '%s' into pool name and image " "name"), src->path); - goto cleanup; + return -1; } src->volume = src->path; if (VIR_STRDUP(src->path, tmp + 1) < 0) - goto cleanup; + return -1; tmp[0] = '\0'; } @@ -8913,16 +8864,13 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, src->configFile = virXPathString("string(./config/@file)", ctxt); if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts) < 0) - goto cleanup; + return -1; virStorageSourceNetworkAssignDefaultPorts(src); virStorageSourceInitiatorParseXML(ctxt, &src->initiator); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -9236,20 +9184,19 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, virDomainXMLOptionPtr xmlopt) { xmlNodePtr mirrorNode; - int ret = -1; VIR_AUTOFREE(char *) mirrorFormat = NULL; VIR_AUTOFREE(char *) mirrorType = NULL; VIR_AUTOFREE(char *) ready = NULL; VIR_AUTOFREE(char *) blockJob = NULL; if (!(def->mirror = virStorageSourceNew())) - goto cleanup; + return -1; if ((blockJob = virXMLPropString(cur, "job"))) { if ((def->mirrorJob = virDomainBlockJobTypeFromString(blockJob)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror job type '%s'"), blockJob); - goto cleanup; + return -1; } } else { def->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; @@ -9260,7 +9207,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror backing store type '%s'"), mirrorType); - goto cleanup; + return -1; } mirrorFormat = virXPathString("string(./mirror/format/@type)", ctxt); @@ -9268,12 +9215,12 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror requires source element")); - goto cleanup; + return -1; } if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror, flags, xmlopt) < 0) - goto cleanup; + return -1; } else { /* For back-compat reasons, we handle a file name * encoded as attributes, even though we prefer @@ -9283,13 +9230,13 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (!def->mirror->path) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror requires file name")); - goto cleanup; + return -1; } if (def->mirrorJob != VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror without type only supported " "by copy job")); - goto cleanup; + return -1; } mirrorFormat = virXMLPropString(cur, "format"); } @@ -9299,7 +9246,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (def->mirror->format <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror format value '%s'"), mirrorFormat); - goto cleanup; + return -1; } } @@ -9307,13 +9254,10 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, (def->mirrorState = virDomainDiskMirrorStateTypeFromString(ready)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown mirror ready state %s"), ready); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -9327,7 +9271,7 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (cyls)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9336,7 +9280,7 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.heads) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (heads)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9345,7 +9289,7 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.sectors) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (secs)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9356,14 +9300,11 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid translation value '%s'"), tmp); - goto error; + return -1; } } return 0; - - error: - return -1; } @@ -9507,7 +9448,6 @@ static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, xmlNodePtr cur) { - int ret = -1; VIR_AUTOFREE(char *) tmp = NULL; def->driverName = virXMLPropString(cur, "name"); @@ -9516,7 +9456,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->cachemode = virDomainDiskCacheTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk cache mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9524,7 +9464,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->error_policy = virDomainDiskErrorPolicyTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk error policy '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9533,7 +9473,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->rerror_policy == VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk read error policy '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9541,7 +9481,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->iomode = virDomainDiskIoTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk io mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9549,7 +9489,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->ioeventfd = virTristateSwitchTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk ioeventfd mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9557,7 +9497,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->event_idx = virTristateSwitchTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk event_idx mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9565,7 +9505,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->copy_on_read = virTristateSwitchTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk copy_on_read mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9573,7 +9513,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->discard = virDomainDiskDiscardTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk discard mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9583,7 +9523,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("Invalid iothread attribute in disk driver element: %s"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9595,7 +9535,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, if ((def->src->format = virStorageFileFormatTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown driver format value '%s'"), tmp); - goto cleanup; + return -1; } } @@ -9606,7 +9546,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, (def->detect_zeroes = virDomainDiskDetectZeroesTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown driver detect_zeroes value '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -9615,13 +9555,10 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("'queues' attribute must be positive number: %s"), tmp); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -10117,7 +10054,6 @@ virDomainParseScaledValue(const char *xpath, unsigned long long max, bool required) { - int ret = -1; unsigned long long bytes; VIR_AUTOFREE(char *) xpath_full = NULL; VIR_AUTOFREE(char *) unit = NULL; @@ -10125,18 +10061,16 @@ virDomainParseScaledValue(const char *xpath, *val = 0; if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) - goto cleanup; + return -1; bytes_str = virXPathString(xpath_full, ctxt); if (!bytes_str) { - if (!required) { - ret = 0; - } else { - virReportError(VIR_ERR_XML_ERROR, - _("missing element or attribute '%s'"), - xpath); - } - goto cleanup; + if (!required) + return 0; + virReportError(VIR_ERR_XML_ERROR, + _("missing element or attribute '%s'"), + xpath); + return -1; } VIR_FREE(xpath_full); @@ -10144,23 +10078,21 @@ virDomainParseScaledValue(const char *xpath, virReportError(VIR_ERR_XML_ERROR, _("Invalid value '%s' for element or attribute '%s'"), bytes_str, xpath); - goto cleanup; + return -1; } if ((units_xpath && virAsprintf(&xpath_full, "string(%s)", units_xpath) < 0) || (!units_xpath && virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0)) - goto cleanup; + return -1; unit = virXPathString(xpath_full, ctxt); if (virScaleInteger(&bytes, unit, scale, max) < 0) - goto cleanup; + return -1; *val = bytes; - ret = 1; - cleanup: - return ret; + return 1; } @@ -12034,7 +11966,6 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, xmlNodePtr cur, unsigned int flags) { - int ret = -1; xmlNodePtr child; unsigned int port; VIR_AUTOFREE(char *) targetType = virXMLPropString(cur, "type"); @@ -12049,7 +11980,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown target type '%s' specified for character device"), targetType); - goto error; + return -1; } child = cur->children; @@ -12067,7 +11998,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown target model '%s' specified for character device"), targetModel); - goto error; + return -1; } switch (def->deviceType) { @@ -12078,37 +12009,37 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, portStr = virXMLPropString(cur, "port"); if (VIR_ALLOC(def->target.addr) < 0) - goto error; + return -1; if (addrStr == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("guestfwd channel does not " "define a target address")); - goto error; + return -1; } if (virSocketAddrParse(def->target.addr, addrStr, AF_UNSPEC) < 0) - goto error; + return -1; if (def->target.addr->data.stor.ss_family != AF_INET) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("guestfwd channel only supports " "IPv4 addresses")); - goto error; + return -1; } if (portStr == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("guestfwd channel does " "not define a target port")); - goto error; + return -1; } if (virStrToLong_ui(portStr, NULL, 10, &port) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid port number: %s"), portStr); - goto error; + return -1; } virSocketAddrSetPort(def->target.addr, port); @@ -12127,7 +12058,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("invalid channel state value '%s'"), stateStr); - goto error; + return -1; } def->state = tmp; @@ -12148,16 +12079,13 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("Invalid port number: %s"), portStr); - goto error; + return -1; } def->target.port = port; break; } - - ret = 0; - error: - return ret; + return 0; } typedef enum { @@ -12176,19 +12104,17 @@ typedef enum { static int virDomainChrSourceDefParseMode(xmlNodePtr source) { - int ret = -1; VIR_AUTOFREE(char *) mode = virXMLPropString(source, "mode"); if (!mode || STREQ(mode, "connect")) { - ret = VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; + return VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; } else if (STREQ(mode, "bind")) { - ret = VIR_DOMAIN_CHR_SOURCE_MODE_BIND; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown source mode '%s'"), mode); + return VIR_DOMAIN_CHR_SOURCE_MODE_BIND; } - return ret; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown source mode '%s'"), mode); + return -1; } @@ -12203,7 +12129,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, VIR_AUTOFREE(char *) tmp = NULL; if ((mode = virDomainChrSourceDefParseMode(source)) < 0) - goto error; + return -1; def->data.tcp.listen = mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND; def->data.tcp.host = virXMLPropString(source, "host"); @@ -12214,7 +12140,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("unknown chardev 'tls' setting '%s'"), tmp); - goto error; + return -1; } VIR_FREE(tmp); } @@ -12225,7 +12151,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("Invalid tlsFromConfig value: %s"), tmp); - goto error; + return -1; } def->data.tcp.tlsFromConfig = !!tmpVal; } @@ -12233,13 +12159,10 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, if (virDomainChrSourceReconnectDefParseXML(&def->data.tcp.reconnect, source, ctxt) < 0) { - goto error; + return -1; } return 0; - - error: - return -1; } @@ -13575,7 +13498,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - int ret = -1; VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); VIR_AUTOFREE(char *) websocket = virXMLPropString(node, "websocket"); VIR_AUTOFREE(char *) websocketGenerated = virXMLPropString(node, "websocketGenerated"); @@ -13583,13 +13505,13 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto cleanup; + return -1; if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc port %s"), port); - goto cleanup; + return -1; } /* Legacy compat syntax, used -1 for auto-port */ if (def->data.vnc.port == -1) { @@ -13618,7 +13540,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, &def->data.vnc.websocket) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc WebSocket port %s"), websocket); - goto cleanup; + return -1; } } @@ -13633,7 +13555,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown vnc display sharing policy '%s'"), sharePolicy); - goto cleanup; + return -1; } else { def->data.vnc.sharePolicy = policy; } @@ -13643,11 +13565,9 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, def->type) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -13713,20 +13633,19 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - int ret = -1; VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); VIR_AUTOFREE(char *) replaceUser = virXMLPropString(node, "replaceUser"); VIR_AUTOFREE(char *) multiUser = virXMLPropString(node, "multiUser"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; + return -1; if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse rdp port %s"), port); - goto error; + return -1; } /* Legacy compat syntax, used -1 for auto-port */ if (def->data.rdp.port == -1) @@ -13749,9 +13668,7 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, if (STREQ_NULLABLE(multiUser, "yes")) def->data.rdp.multiUser = true; - ret = 0; - error: - return ret; + return 0; } @@ -13759,7 +13676,6 @@ static int virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, xmlNodePtr node) { - int ret = -1; VIR_AUTOFREE(char *) fullscreen = virXMLPropString(node, "fullscreen"); if (fullscreen != NULL) { @@ -13770,7 +13686,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - goto cleanup; + return -1; } } else { def->data.desktop.fullscreen = false; @@ -13778,9 +13694,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, def->data.desktop.display = virXMLPropString(node, "display"); - ret = 0; - cleanup: - return ret; + return 0; } @@ -13792,20 +13706,19 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, { xmlNodePtr cur; int defaultModeVal; - int ret = -1; VIR_AUTOFREE(char *) port = virXMLPropString(node, "port"); VIR_AUTOFREE(char *) tlsPort = virXMLPropString(node, "tlsPort"); VIR_AUTOFREE(char *) autoport = virXMLPropString(node, "autoport"); VIR_AUTOFREE(char *) defaultMode = virXMLPropString(node, "defaultMode"); if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; + return -1; if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice port %s"), port); - goto error; + return -1; } } else { def->data.spice.port = 0; @@ -13815,7 +13728,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice tlsPort %s"), tlsPort); - goto error; + return -1; } } else { def->data.spice.tlsPort = 0; @@ -13831,7 +13744,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown default spice channel mode %s"), defaultMode); - goto error; + return -1; } def->data.spice.defaultMode = defaultModeVal; } @@ -13850,7 +13763,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, def->type) < 0) - goto error; + return -1; cur = node->children; while (cur != NULL) { @@ -13866,20 +13779,20 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!name || !mode) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice channel missing name/mode")); - goto error; + return -1; } if ((nameval = virDomainGraphicsSpiceChannelNameTypeFromString(name)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel name %s"), name); - goto error; + return -1; } if ((modeval = virDomainGraphicsSpiceChannelModeTypeFromString(mode)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel mode %s"), mode); - goto error; + return -1; } def->data.spice.channels[nameval] = modeval; @@ -13890,7 +13803,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice image missing compression")); - goto error; + return -1; } if ((compressionVal = @@ -13898,7 +13811,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice image compression %s"), compression); - goto error; + return -1; } def->data.spice.image = compressionVal; @@ -13909,7 +13822,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice jpeg missing compression")); - goto error; + return -1; } if ((compressionVal = @@ -13917,7 +13830,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice jpeg compression %s"), compression); - goto error; + return -1; } def->data.spice.jpeg = compressionVal; @@ -13928,7 +13841,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice zlib missing compression")); - goto error; + return -1; } if ((compressionVal = @@ -13936,7 +13849,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice zlib compression %s"), compression); - goto error; + return -1; } def->data.spice.zlib = compressionVal; @@ -13947,15 +13860,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice playback missing compression")); - goto error; + return -1; } if ((compressionVal = virTristateSwitchTypeFromString(compression)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice playback compression")); - goto error; - + return -1; } def->data.spice.playback = compressionVal; @@ -13966,14 +13878,13 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice streaming missing mode")); - goto error; + return -1; } if ((modeVal = virDomainGraphicsSpiceStreamingModeTypeFromString(mode)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice streaming mode")); - goto error; - + return -1; } def->data.spice.streaming = modeVal; @@ -13984,14 +13895,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!copypaste) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice clipboard missing copypaste")); - goto error; + return -1; } if ((copypasteVal = virTristateBoolTypeFromString(copypaste)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown copypaste value '%s'"), copypaste); - goto error; + return -1; } def->data.spice.copypaste = copypasteVal; @@ -14002,14 +13913,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice filetransfer missing enable")); - goto error; + return -1; } if ((enableVal = virTristateBoolTypeFromString(enable)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - goto error; + return -1; } def->data.spice.filetransfer = enableVal; @@ -14021,14 +13932,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice gl element missing enable")); - goto error; + return -1; } if ((enableVal = virTristateBoolTypeFromString(enable)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - goto error; + return -1; } def->data.spice.gl = enableVal; @@ -14041,14 +13952,14 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice mouse missing mode")); - goto error; + return -1; } if ((modeVal = virDomainGraphicsSpiceMouseModeTypeFromString(mode)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mouse mode value '%s'"), mode); - goto error; + return -1; } def->data.spice.mousemode = modeVal; @@ -14057,9 +13968,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, cur = cur->next; } - ret = 0; - error: - return ret; + return 0; } @@ -15587,7 +15496,6 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, const char *xpath, int *val) { - int ret = -1; VIR_AUTOFREE(char *) tmp = virXPathString(xpath, ctxt); if (tmp) { @@ -15595,13 +15503,11 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, if (*val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown PM state value %s"), tmp); - goto cleanup; + return -1; } } - ret = 0; - cleanup: - return ret; + return 0; } @@ -15610,44 +15516,40 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, xmlNodePtr node) { int event; - int ret = -1; VIR_AUTOFREE(char *) name = NULL; VIR_AUTOFREE(char *) enabled = NULL; if (!(name = virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing perf event name")); - goto cleanup; + return -1; } if ((event = virPerfEventTypeFromString(name)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("'unsupported perf event '%s'"), name); - goto cleanup; + return -1; } if (perf->events[event] != VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, _("perf event '%s' was already specified"), name); - goto cleanup; + return -1; } if (!(enabled = virXMLPropString(node, "enabled"))) { virReportError(VIR_ERR_XML_ERROR, _("missing state of perf event '%s'"), name); - goto cleanup; + return -1; } if ((perf->events[event] = virTristateBoolTypeFromString(enabled)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid state '%s' of perf event '%s'"), enabled, name); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -15655,7 +15557,6 @@ virDomainPerfDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt) { size_t i; - int ret = -1; int n; VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; @@ -15664,13 +15565,10 @@ virDomainPerfDefParseXML(virDomainDefPtr def, for (i = 0; i < n; i++) { if (virDomainPerfEventDefParseXML(&def->perf, nodes[i]) < 0) - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } static int @@ -17676,13 +17574,12 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, xmlNodePtr node; size_t i; int n; - int ret = -1; VIR_AUTOFREE(char *) tmp = NULL; VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; /* analysis of the boot devices */ if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) - goto cleanup; + return -1; for (i = 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) { int val; @@ -17690,14 +17587,14 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing boot device")); - goto cleanup; + return -1; } if ((val = virDomainBootTypeFromString(dev)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown boot device '%s'"), dev); VIR_FREE(dev); - goto cleanup; + return -1; } VIR_FREE(dev); def->os.bootDevs[def->os.nBootDevs++] = val; @@ -17725,7 +17622,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("invalid value for boot menu timeout, " "must be in range [0,65535]")); - goto cleanup; + return -1; } def->os.bm_timeout_set = true; } @@ -17751,16 +17648,13 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("invalid value for rebootTimeout, " "must be in range [-1,65535]")); - goto cleanup; + return -1; } def->os.bios.rt_set = true; } } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -17881,41 +17775,35 @@ virDomainDefParseIOThreads(virDomainDefPtr def, if (tmp && virStrToLong_uip(tmp, NULL, 10, &iothreads) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid iothreads count '%s'"), tmp); - goto error; + return -1; } /* Extract any iothread id's defined */ if ((n = virXPathNodeSet("./iothreadids/iothread", ctxt, &nodes)) < 0) - goto error; + return -1; if (n > iothreads) iothreads = n; if (n && VIR_ALLOC_N(def->iothreadids, n) < 0) - goto error; + return -1; for (i = 0; i < n; i++) { virDomainIOThreadIDDefPtr iothrid = NULL; if (!(iothrid = virDomainIOThreadIDDefParseXML(nodes[i]))) - goto error; + return -1; if (virDomainIOThreadIDFind(def, iothrid->iothread_id)) { virReportError(VIR_ERR_XML_ERROR, _("duplicate iothread id '%u' found"), iothrid->iothread_id); virDomainIOThreadIDDefFree(iothrid); - goto error; + return -1; } def->iothreadids[def->niothreadids++] = iothrid; } - if (virDomainIOThreadIDDefArrayInit(def, iothreads) < 0) - goto error; - - return 0; - - error: - return -1; + return virDomainIOThreadIDDefArrayInit(def, iothreads); } @@ -17930,52 +17818,47 @@ virDomainVcpuPinDefParseXML(virDomainDefPtr def, { virDomainVcpuDefPtr vcpu; unsigned int vcpuid; - int ret = -1; VIR_AUTOFREE(char *) tmp = NULL; if (!(tmp = virXMLPropString(node, "vcpu"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu id in vcpupin")); - goto cleanup; + return -1; } if (virStrToLong_uip(tmp, NULL, 10, &vcpuid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid setting for vcpu '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); if (!(vcpu = virDomainDefGetVcpu(def, vcpuid))) { VIR_WARN("Ignoring vcpupin for missing vcpus"); - ret = 0; - goto cleanup; + return 0; } if (!(tmp = virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for vcpupin")); - goto cleanup; + return -1; } if (vcpu->cpumask) { virReportError(VIR_ERR_INTERNAL_ERROR, _("duplicate vcpupin for vcpu '%d'"), vcpuid); - goto cleanup; + return -1; } if (virBitmapParse(tmp, &vcpu->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; if (virBitmapIsAllClear(vcpu->cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -17987,7 +17870,6 @@ static int virDomainIOThreadPinDefParseXML(xmlNodePtr node, virDomainDefPtr def) { - int ret = -1; virDomainIOThreadIDDefPtr iothrid; unsigned int iothreadid; VIR_AUTOFREE(char *) tmp = NULL; @@ -17996,57 +17878,54 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, if (!(tmp = virXMLPropString(node, "iothread"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing iothread id in iothreadpin")); - goto cleanup; + return -1; } if (virStrToLong_uip(tmp, NULL, 10, &iothreadid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid setting for iothread '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); if (iothreadid == 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("zero is an invalid iothread id value")); - goto cleanup; + return -1; } if (!(iothrid = virDomainIOThreadIDFind(def, iothreadid))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cannot find 'iothread' : %u"), iothreadid); - goto cleanup; + return -1; } if (!(tmp = virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for iothreadpin")); - goto cleanup; + return -1; } if (virBitmapParse(tmp, &cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; if (virBitmapIsAllClear(cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return -1; } if (iothrid->cpumask) { virReportError(VIR_ERR_INTERNAL_ERROR, _("duplicate iothreadpin for same iothread '%u'"), iothreadid); - goto cleanup; + return -1; } VIR_STEAL_PTR(iothrid->cpumask, cpumask); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -18068,17 +17947,15 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) } if (virBitmapParse(tmp, &def, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return NULL; if (virBitmapIsAllClear(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return NULL; } VIR_STEAL_PTR(ret, def); - - cleanup: return ret; } @@ -18317,7 +18194,6 @@ static int virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader) { - int ret = -1; VIR_AUTOFREE(char *) readonly_str = NULL; VIR_AUTOFREE(char *) secure_str = NULL; VIR_AUTOFREE(char *) type_str = NULL; @@ -18331,14 +18207,14 @@ virDomainLoaderDefParseXML(xmlNodePtr node, (loader->readonly = virTristateBoolTypeFromString(readonly_str)) <= 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown readonly value: %s"), readonly_str); - goto cleanup; + return -1; } if (secure_str && (loader->secure = virTristateBoolTypeFromString(secure_str)) <= 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown secure value: %s"), secure_str); - goto cleanup; + return -1; } if (type_str) { @@ -18346,14 +18222,12 @@ virDomainLoaderDefParseXML(xmlNodePtr node, if ((type = virDomainLoaderTypeFromString(type_str)) < 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown type value: %s"), type_str); - goto cleanup; + return -1; } loader->type = type; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -18505,7 +18379,6 @@ virDomainVcpuParse(virDomainDefPtr def, size_t i; unsigned int maxvcpus; unsigned int vcpus; - int ret = -1; VIR_AUTOFREE(char *) tmp = NULL; VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; @@ -18516,7 +18389,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &maxvcpus) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("maximum vcpus count must be an integer")); - goto cleanup; + return -1; } VIR_FREE(tmp); } @@ -18525,7 +18398,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &vcpus) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("current vcpus count must be an integer")); - goto cleanup; + return -1; } VIR_FREE(tmp); } else { @@ -18539,7 +18412,7 @@ virDomainVcpuParse(virDomainDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported CPU placement mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); } else { @@ -18550,12 +18423,12 @@ virDomainVcpuParse(virDomainDefPtr def, tmp = virXMLPropString(vcpuNode, "cpuset"); if (tmp) { if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; if (virBitmapIsAllClear(def->cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -18564,10 +18437,10 @@ virDomainVcpuParse(virDomainDefPtr def, } if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0) - goto cleanup; + return -1; if ((n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) - goto cleanup; + return -1; if (n) { /* if individual vcpu states are provided take them as master */ @@ -18583,7 +18456,7 @@ virDomainVcpuParse(virDomainDefPtr def, virStrToLong_uip(tmp, NULL, 10, &id) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing or invalid vcpu id")); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -18592,7 +18465,7 @@ virDomainVcpuParse(virDomainDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("vcpu id '%u' is out of range of maximum " "vcpu count"), id); - goto cleanup; + return -1; } vcpu = virDomainDefGetVcpu(def, id); @@ -18600,13 +18473,13 @@ virDomainVcpuParse(virDomainDefPtr def, if (!(tmp = virXMLPropString(nodes[i], "enabled"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu enabled state")); - goto cleanup; + return -1; } if ((state = virTristateBoolTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid vcpu 'enabled' value '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); @@ -18617,7 +18490,7 @@ virDomainVcpuParse(virDomainDefPtr def, if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid vcpu 'hotpluggable' value '%s'"), tmp); - goto cleanup; + return -1; } vcpu->hotpluggable = hotpluggable; VIR_FREE(tmp); @@ -18627,7 +18500,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_uip(tmp, NULL, 10, &order) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid vcpu order")); - goto cleanup; + return -1; } vcpu->order = order; VIR_FREE(tmp); @@ -18635,13 +18508,10 @@ virDomainVcpuParse(virDomainDefPtr def, } } else { if (virDomainDefSetVcpus(def, vcpus) < 0) - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -18650,7 +18520,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def, xmlXPathContextPtr ctxt) { char *name = NULL; - int ret = -1; size_t i; int n; VIR_AUTOFREE(xmlNodePtr *) nodes = NULL; @@ -18673,34 +18542,34 @@ virDomainDefParseBootOptions(virDomainDefPtr def, def->os.initgroup = virXPathString("string(./os/initgroup[1])", ctxt); if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) - goto error; + return -1; if (VIR_ALLOC_N(def->os.initargv, n+1) < 0) - goto error; + return -1; for (i = 0; i < n; i++) { if (!nodes[i]->children || !nodes[i]->children->content) { virReportError(VIR_ERR_XML_ERROR, "%s", _("No data supplied for <initarg> element")); - goto error; + return -1; } if (VIR_STRDUP(def->os.initargv[i], (const char*) nodes[i]->children->content) < 0) - goto error; + return -1; } def->os.initargv[n] = NULL; VIR_FREE(nodes); if ((n = virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0) - goto error; + return -1; if (VIR_ALLOC_N(def->os.initenv, n+1) < 0) - goto error; + return -1; for (i = 0; i < n; i++) { if (!(name = virXMLPropString(nodes[i], "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("No name supplied for <initenv> element")); - goto error; + return -1; } if (!nodes[i]->children || @@ -18708,16 +18577,16 @@ virDomainDefParseBootOptions(virDomainDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("No value supplied for <initenv name='%s'> element"), name); - goto error; + return -1; } if (VIR_ALLOC(def->os.initenv[i]) < 0) - goto error; + return -1; def->os.initenv[i]->name = name; if (VIR_STRDUP(def->os.initenv[i]->value, (const char*) nodes[i]->children->content) < 0) - goto error; + return -1; } def->os.initenv[n] = NULL; VIR_FREE(nodes); @@ -18736,10 +18605,10 @@ virDomainDefParseBootOptions(virDomainDefPtr def, def->os.root = virXPathString("string(./os/root[1])", ctxt); if ((loader_node = virXPathNode("./os/loader[1]", ctxt))) { if (VIR_ALLOC(def->os.loader) < 0) - goto error; + return -1; if (virDomainLoaderDefParseXML(loader_node, def->os.loader) < 0) - goto error; + return -1; def->os.loader->nvram = virXPathString("string(./os/nvram[1])", ctxt); def->os.loader->templt = virXPathString("string(./os/nvram[1]/@template)", ctxt); @@ -18748,12 +18617,12 @@ virDomainDefParseBootOptions(virDomainDefPtr def, if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { if ((n = virXPathNodeSet("./os/acpi/table", ctxt, &nodes)) < 0) - goto error; + return -1; if (n > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Only one acpi table is supported")); - goto error; + return -1; } if (n == 1) { @@ -18762,30 +18631,26 @@ virDomainDefParseBootOptions(virDomainDefPtr def, if (!tmp) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing acpi table type")); - goto error; + return -1; } if (STREQ_NULLABLE(tmp, "slic")) { VIR_FREE(tmp); tmp = virXMLNodeContentString(nodes[0]); def->os.slic_table = virFileSanitizePath(tmp); - VIR_FREE(tmp); } else { virReportError(VIR_ERR_XML_ERROR, _("Unknown acpi table type: %s"), tmp); - goto error; + return -1; } } if (virDomainDefParseBootXML(ctxt, def) < 0) - goto error; + return -1; } - ret = 0; - - error: - return ret; + return 0; } @@ -18794,29 +18659,26 @@ virDomainResctrlParseVcpus(virDomainDefPtr def, xmlNodePtr node, virBitmapPtr *vcpus) { - int ret = -1; VIR_AUTOFREE(char *) vcpus_str = NULL; vcpus_str = virXMLPropString(node, "vcpus"); if (!vcpus_str) { virReportError(VIR_ERR_XML_ERROR, _("Missing %s attribute 'vcpus'"), node->name); - goto cleanup; + return -1; } if (virBitmapParse(vcpus_str, vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid %s attribute 'vcpus' value '%s'"), node->name, vcpus_str); - goto cleanup; + return -1; } /* We need to limit the bitmap to number of vCPUs. If there's nothing left, * then we can just clean up and return 0 immediately */ virBitmapShrink(*vcpus, def->maxvcpus); - ret = 0; - cleanup: - return ret; + return 0; } @@ -19219,7 +19081,6 @@ virDomainDefParseCaps(virDomainDefPtr def, virCapsPtr caps, unsigned int flags) { - int ret = -1; VIR_AUTOFREE(char *) virttype = NULL; VIR_AUTOFREE(char *) arch = NULL; VIR_AUTOFREE(char *) ostype = NULL; @@ -19237,12 +19098,12 @@ virDomainDefParseCaps(virDomainDefPtr def, if (!virttype) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain type attribute")); - goto cleanup; + return -1; } if ((def->virtType = virDomainVirtTypeFromString(virttype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain type %s"), virttype); - goto cleanup; + return -1; } if (!ostype) { @@ -19251,13 +19112,13 @@ virDomainDefParseCaps(virDomainDefPtr def, } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("an os <type> must be specified")); - goto cleanup; + return -1; } } else { if ((def->os.type = virDomainOSTypeFromString(ostype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown OS type '%s'"), ostype); - goto cleanup; + return -1; } } @@ -19274,7 +19135,7 @@ virDomainDefParseCaps(virDomainDefPtr def, if (arch && !(def->os.arch = virArchFromString(arch))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown architecture %s"), arch); - goto cleanup; + return -1; } if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, @@ -19282,19 +19143,17 @@ virDomainDefParseCaps(virDomainDefPtr def, def->virtType, NULL, NULL))) { if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - goto cleanup; + return -1; virResetLastError(); } else { if (!def->os.arch) def->os.arch = capsdata->arch; if ((!def->os.machine && VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -26138,7 +25997,6 @@ static int virDomainMemorySourceDefFormat(virBufferPtr buf, virDomainMemoryDefPtr def) { - int ret = -1; VIR_AUTOFREE(char *) bitmap = NULL; if (!def->pagesize && !def->sourceNodes && !def->nvdimmPath) @@ -26151,7 +26009,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (def->sourceNodes) { if (!(bitmap = virBitmapFormat(def->sourceNodes))) - goto cleanup; + return -1; virBufferAsprintf(buf, "<nodemask>%s</nodemask>\n", bitmap); } @@ -26180,10 +26038,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</source>\n"); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -27603,7 +27458,6 @@ virDomainCpuDefFormat(virBufferPtr buf, { virDomainVcpuDefPtr vcpu; size_t i; - int ret = -1; VIR_AUTOFREE(char *) cpumask = NULL; virBufferAddLit(buf, "<vcpu"); @@ -27612,7 +27466,7 @@ virDomainCpuDefFormat(virBufferPtr buf, if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) { if ((cpumask = virBitmapFormat(def->cpumask)) == NULL) - goto cleanup; + return -1; virBufferAsprintf(buf, " cpuset='%s'", cpumask); } if (virDomainDefHasVcpusOffline(def)) @@ -27640,10 +27494,7 @@ virDomainCpuDefFormat(virBufferPtr buf, virBufferAddLit(buf, "</vcpus>\n"); } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -28839,29 +28690,25 @@ virDomainSaveXML(const char *configDir, const char *xml) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - int ret = -1; VIR_AUTOFREE(char *) configFile = NULL; if (!configDir) return 0; if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL) - goto cleanup; + return -1; if (virFileMakePath(configDir) < 0) { virReportSystemError(errno, _("cannot create config directory '%s'"), configDir); - goto cleanup; + return -1; } virUUIDFormat(def->uuid, uuidstr); - ret = virXMLSaveFile(configFile, - virXMLPickShellSafeComment(def->name, uuidstr), "edit", - xml); - - cleanup: - return ret; + return virXMLSaveFile(configFile, + virXMLPickShellSafeComment(def->name, uuidstr), "edit", + xml); } int @@ -28869,18 +28716,12 @@ virDomainSaveConfig(const char *configDir, virCapsPtr caps, virDomainDefPtr def) { - int ret = -1; VIR_AUTOFREE(char *) xml = NULL; if (!(xml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto cleanup; - - if (virDomainSaveXML(configDir, def, xml)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return virDomainSaveXML(configDir, def, xml); } int @@ -28895,18 +28736,12 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST); - int ret = -1; VIR_AUTOFREE(char *) xml = NULL; if (!(xml = virDomainObjFormat(xmlopt, obj, caps, flags))) - goto cleanup; - - if (virDomainSaveXML(statusDir, obj->def, xml)) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return virDomainSaveXML(statusDir, obj->def, xml); } @@ -28915,15 +28750,14 @@ virDomainDeleteConfig(const char *configDir, const char *autostartDir, virDomainObjPtr dom) { - int ret = -1; VIR_AUTOFREE(char *) configFile = NULL; VIR_AUTOFREE(char *) autostartLink = NULL; if ((configFile = virDomainConfigFile(configDir, dom->def->name)) == NULL) - goto cleanup; + return -1; if ((autostartLink = virDomainConfigFile(autostartDir, dom->def->name)) == NULL) - goto cleanup; + return -1; /* Not fatal if this doesn't work */ unlink(autostartLink); @@ -28934,13 +28768,10 @@ virDomainDeleteConfig(const char *configDir, virReportSystemError(errno, _("cannot remove config %s"), configFile); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } char @@ -29202,20 +29033,19 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, virDomainDiskDefPathIterator iter, void *opaque) { - int ret = -1; size_t depth = 0; virStorageSourcePtr tmp; VIR_AUTOFREE(char *) brokenRaw = NULL; if (!ignoreOpenFailure) { if (virStorageFileChainGetBroken(disk->src, &brokenRaw) < 0) - goto cleanup; + return -1; if (brokenRaw) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to visit backing chain file %s"), brokenRaw); - goto cleanup; + return -1; } } @@ -29224,16 +29054,13 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, if (virStorageSourceIsLocalStorage(tmp) && tmp->path) { if (iter(disk, tmp->path, depth, opaque) < 0) - goto cleanup; + return -1; } depth++; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -29248,7 +29075,6 @@ virDomainDefCopy(virDomainDefPtr src, void *parseOpaque, bool migratable) { - virDomainDefPtr ret; unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; @@ -29261,9 +29087,7 @@ virDomainDefCopy(virDomainDefPtr src, if (!(xml = virDomainDefFormat(src, caps, format_flags))) return NULL; - ret = virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); - - return ret; + return virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags); } virDomainDefPtr @@ -29687,7 +29511,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, virCapsPtr caps, virDomainXMLOptionPtr xmlopt) { - virDomainDeviceDefPtr ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; int flags = VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_SECURE; int rc = -1; @@ -29767,19 +29590,16 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, _("Copying definition of '%d' type " "is not implemented yet."), src->type); - goto cleanup; + return NULL; } if (rc < 0) - goto cleanup; + return NULL; xmlStr = virBufferContentAndReset(&buf); - ret = virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE | - VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); - - cleanup: - return ret; + return virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, + VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); } @@ -30152,11 +29972,10 @@ virDomainDefGetShortName(const virDomainDef *def) virReportSystemError(errno, "%s", _("Cannot convert wide character string " "back to multi-byte domain name")); - goto cleanup; + return NULL; } ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname)); - cleanup: return ret; } -- 2.20.1

On Wed, Feb 20, 2019 at 01:34:04PM -0500, John Ferlan wrote:
Now that we're using VIR_AUTOFREE there's quite a bit of clean up possible for now unnecessary goto paths.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- Reviewed-by: Erik Skultety <eskultet@redhat.com>

On Fri, Mar 01, 2019 at 01:44:00PM +0100, Erik Skultety wrote:
On Wed, Feb 20, 2019 at 01:34:04PM -0500, John Ferlan wrote:
Now that we're using VIR_AUTOFREE there's quite a bit of clean up possible for now unnecessary goto paths.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- Reviewed-by: Erik Skultety <eskultet@redhat.com>
Since you're cleaning only labels here the following functions have labels that can be dropped too: virDomainDiskTranslateSourcePoolAuth virDomainObjGetMetadata virDomainHugepagesFormatBuf Erik

ping? I also think that w/ Peter's addition of VIR_XPATH_NODE_AUTORESTORE even more changes could be done, but I'd leave those for either Peter to finish what he started or the mythical future someone else. Tks - John On 2/20/19 1:33 PM, John Ferlan wrote:
v1: https://www.redhat.com/archives/libvir-list/2019-February/msg01160.html
Changes since v1:
* Push patch 1
* Split patch 2 to follow code review guidance:
* (Patch1) Pull out virDomainEmulatorPinDefParseXML changes to use VIR_STEAL_PTR * (Patch2) Use VIR_AUTOPTR(virBitmap) * (Patch3) Handle a couple cases where goto's no longer necessary
* Drop Patch 3
* Split Patch 4 to follow code review guidance:
* (Patch4) Remove unused variables * (Patch5) Just use VIR_AUTOFREE * (Patch6) Handle the removal of goto logic that's no longer necessary
John Ferlan (6): conf: Rework virDomainEmulatorPinDefParseXML conf: Use VIR_AUTOPTR(virBitmap) in domain_conf conf: Clean up some unnecessary goto paths conf: Remove a few unused variables in domain_conf conf: Use VIR_AUTOFREE in domain_conf conf: Clean up some unnecessary goto paths
src/conf/domain_conf.c | 1937 ++++++++++++++-------------------------- 1 file changed, 676 insertions(+), 1261 deletions(-)

On Wed, Feb 27, 2019 at 12:31:56PM -0500, John Ferlan wrote:
ping?
I also think that w/ Peter's addition of VIR_XPATH_NODE_AUTORESTORE even more changes could be done, but I'd leave those for either Peter to finish what he started or the mythical future someone else.
I also found some occurrences of virObjectUnref which may be replaced by VIR_AUTOUNREF, so if you wouldn't mind posting a follow up so that we don't need to revisit this module for the same purpose for a while. A few more notes for a potential follow-up: - in virDomainKeyWrapDefParseXML we could introduce a VIR_AUTOFREE helper for keywrap and do VIR_STEALPTR so that we can get rid of the whole cleanup section - virDomainVsockDefNew could make use of VIR_AUTOPTR - virDomainDefBootOrderPostParse could make use of VIR_AUTOPTR - virDomainDefValidateAliases (VIR_AUTOPTR) - virDomainDeviceValidateAliasImpl (VIR_AUTOPTR) - virDomainDiskSourcePoolDefParse (VIR_AUTOPTR) - virSysinfoChassisParseXML (VIR_AUTOPTR) - virDomainCachetuneDefParse (VIR_AUTOUNREF) - virDomainMemorytuneDefParse (VIR_AUTOUNREF) - virDomainDefAddImplicitVideo (VIR_AUTOPTR) And a bunch of others which I didn't bother checking thoroughly. Erik

On 3/1/19 8:38 AM, Erik Skultety wrote:
On Wed, Feb 27, 2019 at 12:31:56PM -0500, John Ferlan wrote:
ping?
I also think that w/ Peter's addition of VIR_XPATH_NODE_AUTORESTORE even more changes could be done, but I'd leave those for either Peter to finish what he started or the mythical future someone else.
I also found some occurrences of virObjectUnref which may be replaced by VIR_AUTOUNREF, so if you wouldn't mind posting a follow up so that we don't need to revisit this module for the same purpose for a while. A few more notes for a potential follow-up:
A bit of history - based on the storage changes I made, I started thinking maybe it's time to just start the process of getting more code to use the VIR_AUTO* stuff. I figured domain_conf would be the most challenging and it's where I started (and before Peter wrote the VIR_AUTOUNREF patches). My initial pass was look for virBitmapPtr and VIR_AUTOFREE. I thought I got most although I do see a couple more that would be possible: * virDomainHugepagesFormatBuf for @nodeset * virDomainChrTargetDefFormat for @addr within TYPE_GUESTFWD * virDomainNetDefFormat for @str, @gueststr, & @hoststr within def->model processing * virDomainChannelDefCheckABIStability for @saddr & @daddr within TYPE_GUESTFWD
- in virDomainKeyWrapDefParseXML we could introduce a VIR_AUTOFREE helper for keywrap and do VIR_STEALPTR so that we can get rid of the whole cleanup section
Sure this is simple enough to do. Hopefully acceptible in one patch at the end of the series and not a multipatch step...
- virDomainVsockDefNew could make use of VIR_AUTOPTR - virDomainDefBootOrderPostParse could make use of VIR_AUTOPTR - virDomainDefValidateAliases (VIR_AUTOPTR) - virDomainDeviceValidateAliasImpl (VIR_AUTOPTR) - virDomainDiskSourcePoolDefParse (VIR_AUTOPTR) - virSysinfoChassisParseXML (VIR_AUTOPTR) - virDomainCachetuneDefParse (VIR_AUTOUNREF) - virDomainMemorytuneDefParse (VIR_AUTOUNREF) - virDomainDefAddImplicitVideo (VIR_AUTOPTR)
VIR_AUTOPTR is beyond the scope of what I was doing and altering all the places for virObjectUnref really could have been done by when VIR_AUTOUNREF was introduced (VIR_XPATH_NODE_AUTORESTORE too). We keep adding this VIR_AUTO* things, but without someone actively trying to complete the work, it will never happen and we'll be continually stuck in this limbo state. For some it's more than first patch type contribution. I don't mind adding VIR_AUTOUNREF since it's already pushed, but adding new VIR_AUTOPTR's is an exercise for someone else eventually as far more than domain_conf would need to be touched in order to do it right. John I'll post a v3 shortly with the diffs requested as part of review and the few extra VIR_AUTOFREE's I found for you to look at.
And a bunch of others which I didn't bother checking thoroughly. Erik
participants (2)
-
Erik Skultety
-
John Ferlan