[PATCH v3 05/10] conf: Use VIR_AUTOFREE in domain_conf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 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 cbaa32e174..c06c52271c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1105,11 +1105,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",
@@ -1167,8 +1167,6 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap,
     ret = 0;
 
  cleanup:
-    VIR_FREE(name);
-    VIR_FREE(state);
     return ret;
 }
 
@@ -1177,8 +1175,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;
@@ -1200,7 +1198,6 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt)
  cleanup:
     if (ret < 0)
         VIR_FREE(def->keywrap);
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -1273,10 +1270,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;
@@ -1308,7 +1305,6 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver,
     ret = 0;
 
  cleanup:
-    VIR_FREE(str);
     return ret;
 }
 
@@ -1350,8 +1346,8 @@ static int
 virDomainBlkioDeviceParseXML(xmlNodePtr root,
                              virBlkioDevicePtr dev)
 {
-    char *c = NULL;
     xmlNodePtr node;
+    VIR_AUTOFREE(char *) c = NULL;
 
     node = root->children;
     while (node) {
@@ -1416,7 +1412,6 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
     return 0;
 
  error:
-    VIR_FREE(c);
     VIR_FREE(dev->path);
     return -1;
 }
@@ -5337,8 +5332,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;
@@ -5367,7 +5362,6 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTRIBUTE_UNUSED,
     ret = 0;
 
  cleanup:
-    VIR_FREE(order);
     return ret;
 }
 
@@ -6888,8 +6882,8 @@ static int
 virDomainDeviceUSBMasterParseXML(xmlNodePtr node,
                                  virDomainDeviceUSBMasterPtr master)
 {
-    char *startport;
     int ret = -1;
+    VIR_AUTOFREE(char *) startport = NULL;
 
     memset(master, 0, sizeof(*master));
 
@@ -6905,7 +6899,6 @@ virDomainDeviceUSBMasterParseXML(xmlNodePtr node,
     ret = 0;
 
  cleanup:
-    VIR_FREE(startport);
     return ret;
 }
 
@@ -6913,9 +6906,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,
@@ -6949,8 +6942,6 @@ virDomainDeviceBootParseXML(xmlNodePtr node,
     ret = 0;
 
  cleanup:
-    VIR_FREE(order);
-    VIR_FREE(loadparm);
     return ret;
 }
 
@@ -6959,8 +6950,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));
 
@@ -6983,8 +6974,6 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node,
 
     ret = 0;
  cleanup:
-    VIR_FREE(iobase);
-    VIR_FREE(irq);
     return ret;
 }
 
@@ -6994,7 +6983,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) {
@@ -7011,15 +7000,11 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node,
                            _("invalid dimm base address '%s'"), tmp);
             goto cleanup;
         }
-
-        VIR_FREE(tmp);
     }
 
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
-
     return ret;
 }
 
@@ -7029,7 +7014,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) {
@@ -7106,7 +7091,6 @@ virDomainDeviceAddressParseXML(xmlNodePtr address,
 
     ret = 0;
  cleanup:
-    VIR_FREE(type);
     return ret;
 }
 
@@ -7137,10 +7121,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);
 
@@ -7222,9 +7206,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
  cleanup:
     if (ret < 0)
         virDomainDeviceInfoClear(info);
-    VIR_FREE(rombar);
-    VIR_FREE(romenabled);
-    VIR_FREE(aliasStr);
     return ret;
 }
 
@@ -7253,9 +7234,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 =
@@ -7264,16 +7245,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
@@ -7285,24 +7263,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;
@@ -7311,27 +7287,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"));
@@ -7344,10 +7317,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"));
@@ -7441,14 +7412,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;
@@ -7479,9 +7449,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;
@@ -7535,8 +7505,6 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
 
  cleanup:
     virStorageNetHostDefClear(&host);
-    VIR_FREE(transport);
-    VIR_FREE(port);
     return ret;
 }
 
@@ -7568,8 +7536,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) {
@@ -7644,9 +7614,6 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
 
     ret = 0;
  cleanup:
-    VIR_FREE(bus);
-    VIR_FREE(target);
-    VIR_FREE(unit);
     return ret;
 }
 
@@ -7726,8 +7693,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 =
@@ -7746,7 +7713,6 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
         ret = virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
 
  cleanup:
-    VIR_FREE(protocol);
     return ret;
 }
 
@@ -7754,10 +7720,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",
@@ -7799,8 +7765,6 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode,
 
     ret = 0;
  cleanup:
-    VIR_FREE(wwpn);
-    VIR_FREE(protocol);
     return ret;
 }
 
@@ -7810,9 +7774,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",
@@ -7836,7 +7800,6 @@ virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def,
     virUUIDFormat(uuid, mdevsrc->uuidstr);
     ret = 0;
  cleanup:
-    VIR_FREE(uuidxml);
     return ret;
 }
 
@@ -7848,17 +7811,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
@@ -8018,12 +7981,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;
 }
 
@@ -8031,12 +7988,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",
@@ -8084,11 +8043,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;
 }
 
@@ -8103,12 +8057,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;
@@ -8133,9 +8087,7 @@ virDomainNetIPInfoParseXML(const char *source,
  cleanup:
     if (ret < 0)
         virNetDevIPInfoClear(def);
-    VIR_FREE(ip);
     virNetDevIPRouteFree(route);
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -8146,8 +8098,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;
@@ -8163,10 +8115,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,
@@ -8178,7 +8128,6 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node,
     ret->rx_max_coalesced_frames = tmp;
 
  cleanup:
-    VIR_FREE(str);
     ctxt->node = save;
     return ret;
 
@@ -8553,8 +8502,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)
@@ -8592,7 +8542,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
@@ -8647,7 +8596,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def,
         virSecurityLabelDefFree(def->seclabels[i - 1]);
     VIR_FREE(def->seclabels);
     def->nseclabels = 0;
-    VIR_FREE(list);
     return -1;
 }
 
@@ -8662,8 +8610,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;
@@ -8731,7 +8679,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
             goto error;
         }
     }
-    VIR_FREE(list);
 
     *nseclabels_rtn = nseclabels;
     *seclabels_rtn = seclabels;
@@ -8742,7 +8689,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
     for (i = 0; i < nseclabels; i++)
         virSecurityDeviceLabelDefFree(seclabels[i]);
     VIR_FREE(seclabels);
-    VIR_FREE(list);
     return -1;
 }
 
@@ -8785,10 +8731,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;
@@ -8833,11 +8779,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:
@@ -8850,9 +8791,9 @@ static int
 virDomainDiskSourcePoolDefParse(xmlNodePtr node,
                                 virStorageSourcePoolDefPtr *srcpool)
 {
-    char *mode = NULL;
     virStorageSourcePoolDefPtr source;
     int ret = -1;
+    VIR_AUTOFREE(char *) mode = NULL;
 
     *srcpool = NULL;
 
@@ -8889,7 +8830,6 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
 
  cleanup:
     virStorageSourcePoolDefFree(source);
-    VIR_FREE(mode);
     return ret;
 }
 
@@ -8900,11 +8840,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",
@@ -8981,9 +8921,6 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
     ret = 0;
 
  cleanup:
-    VIR_FREE(tlsCfg);
-    VIR_FREE(haveTLS);
-    VIR_FREE(protocol);
     return ret;
 }
 
@@ -9138,11 +9075,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;
@@ -9203,9 +9140,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
     ret = 0;
 
  cleanup:
-    VIR_FREE(type);
-    VIR_FREE(format);
-    VIR_FREE(idx);
     ctxt->node = save_ctxt;
     return ret;
 }
@@ -9301,11 +9235,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;
@@ -9378,10 +9312,6 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def,
     ret = 0;
 
  cleanup:
-    VIR_FREE(ready);
-    VIR_FREE(blockJob);
-    VIR_FREE(mirrorType);
-    VIR_FREE(mirrorFormat);
     return ret;
 }
 
@@ -9390,7 +9320,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) {
@@ -9427,13 +9357,11 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def,
                            tmp);
             goto error;
         }
-        VIR_FREE(tmp);
     }
 
     return 0;
 
  error:
-    VIR_FREE(tmp);
     return -1;
 }
 
@@ -9578,8 +9506,8 @@ static int
 virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
                                xmlNodePtr cur)
 {
-    char *tmp = NULL;
     int ret = -1;
+    VIR_AUTOFREE(char *) tmp = NULL;
 
     def->driverName = virXMLPropString(cur, "name");
 
@@ -9688,13 +9616,10 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
                        tmp);
         goto cleanup;
     }
-    VIR_FREE(tmp);
 
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
-
     return ret;
 }
 
@@ -9743,26 +9668,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;
@@ -10150,25 +10075,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;
 
@@ -10209,11 +10116,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)
@@ -10252,9 +10159,6 @@ virDomainParseScaledValue(const char *xpath,
     *val = bytes;
     ret = 1;
  cleanup:
-    VIR_FREE(bytes_str);
-    VIR_FREE(xpath_full);
-    VIR_FREE(unit);
     return ret;
 }
 
@@ -10455,27 +10359,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;
 
@@ -10614,20 +10518,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: {
@@ -10790,22 +10692,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:
@@ -10834,15 +10720,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;
 
@@ -10988,16 +10874,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:
@@ -11019,11 +10895,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;
@@ -11122,16 +10998,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) {
@@ -11173,11 +11049,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;
@@ -11220,9 +11091,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;
 
@@ -11246,7 +11117,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def,
                                    tmp);
                     goto cleanup;
                 }
-                VIR_FREE(tmp);
             } else {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                                _("missing timeout for chardev with "
@@ -11259,7 +11129,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def,
     ret = 0;
  cleanup:
     ctxt->node = saveNode;
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -11279,46 +11148,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;
@@ -12066,44 +11935,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:
@@ -12203,11 +12036,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,
@@ -12323,12 +12156,6 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
 
     ret = 0;
  error:
-    VIR_FREE(targetType);
-    VIR_FREE(targetModel);
-    VIR_FREE(addrStr);
-    VIR_FREE(portStr);
-    VIR_FREE(stateStr);
-
     return ret;
 }
 
@@ -12348,8 +12175,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;
@@ -12360,7 +12187,6 @@ virDomainChrSourceDefParseMode(xmlNodePtr source)
                        _("Unknown source mode '%s'"), mode);
     }
 
-    VIR_FREE(mode);
     return ret;
 }
 
@@ -12372,8 +12198,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;
@@ -12401,7 +12227,6 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def,
             goto error;
         }
         def->data.tcp.tlsFromConfig = !!tmpVal;
-        VIR_FREE(tmp);
     }
 
     if (virDomainChrSourceReconnectDefParseXML(&def->data.tcp.reconnect,
@@ -12413,7 +12238,6 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def,
     return 0;
 
  error:
-    VIR_FREE(tmp);
     return -1;
 }
 
@@ -12468,7 +12292,7 @@ static int
 virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def,
                                xmlNodePtr source)
 {
-    char *append = NULL;
+    VIR_AUTOFREE(char *) append = NULL;
 
     def->data.file.path = virXMLPropString(source, "path");
 
@@ -12477,11 +12301,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;
 }
 
@@ -12490,7 +12312,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;
@@ -12500,11 +12322,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;
 }
 
@@ -12513,7 +12333,7 @@ static int
 virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def,
                               xmlNodePtr log)
 {
-    char *append = NULL;
+    VIR_AUTOFREE(char *) append = NULL;
 
     def->logfile = virXMLPropString(log, "file");
 
@@ -12522,11 +12342,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;
 }
 
@@ -12774,10 +12592,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;
@@ -12844,8 +12662,6 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    VIR_FREE(type);
-
     return def;
 
  error:
@@ -12861,10 +12677,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;
@@ -12976,9 +12792,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    VIR_FREE(mode);
-    VIR_FREE(type);
-
     return def;
 
  error:
@@ -13009,14 +12822,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;
@@ -13089,11 +12902,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;
 
@@ -13109,7 +12917,7 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xmlopt,
                           unsigned int flags)
 {
     virDomainPanicDefPtr panic;
-    char *model = NULL;
+    VIR_AUTOFREE(char *) model = NULL;
 
     if (VIR_ALLOC(panic) < 0)
         return NULL;
@@ -13127,7 +12935,6 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    VIR_FREE(model);
     return panic;
 
  error:
@@ -13146,9 +12953,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;
@@ -13276,10 +13083,6 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(evdev);
-    VIR_FREE(type);
-    VIR_FREE(bus);
-
     ctxt->node = save;
     return def;
 
@@ -13297,7 +13100,7 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlopt,
                         unsigned int flags)
 {
     virDomainHubDefPtr def;
-    char *type = NULL;
+    VIR_AUTOFREE(char *) type = NULL;
 
     if (VIR_ALLOC(def) < 0)
         return NULL;
@@ -13320,8 +13123,6 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(type);
-
     return def;
 
  error:
@@ -13336,16 +13137,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;
@@ -13448,11 +13248,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;
@@ -13468,8 +13263,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");
 
@@ -13497,11 +13292,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 */
@@ -13516,10 +13309,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 &&
@@ -13557,16 +13348,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");
@@ -13691,14 +13482,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;
 }
 
@@ -13709,12 +13492,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;
 
@@ -13738,7 +13521,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
 
             def->nListens++;
         }
-        VIR_FREE(listenNodes);
     }
 
     /* If no <listen/> element was found in XML for backward compatibility
@@ -13781,8 +13563,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
     ret = 0;
  cleanup:
     virDomainGraphicsListenDefClear(&newListen);
-    VIR_FREE(listenNodes);
-    VIR_FREE(socketPath);
     ctxt->node = save;
     return ret;
 }
@@ -13794,12 +13574,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;
@@ -13866,11 +13646,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(port);
-    VIR_FREE(autoport);
-    VIR_FREE(websocket);
-    VIR_FREE(websocketGenerated);
-    VIR_FREE(sharePolicy);
     return ret;
 }
 
@@ -13881,11 +13656,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;
 
@@ -13926,8 +13701,6 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(fullscreen);
-    VIR_FREE(enable);
     ctxt->node = save;
     return ret;
 }
@@ -13939,11 +13712,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;
@@ -13977,10 +13750,6 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def,
 
     ret = 0;
  error:
-    VIR_FREE(port);
-    VIR_FREE(autoport);
-    VIR_FREE(replaceUser);
-    VIR_FREE(multiUser);
     return ret;
 }
 
@@ -13989,8 +13758,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")) {
@@ -14010,7 +13779,6 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(fullscreen);
     return ret;
 }
 
@@ -14022,12 +13790,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;
@@ -14087,16 +13855,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;
                 }
 
@@ -14104,25 +13872,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",
@@ -14135,15 +13897,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",
@@ -14156,15 +13916,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",
@@ -14177,15 +13935,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",
@@ -14197,16 +13953,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",
@@ -14217,16 +13971,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",
@@ -14238,15 +13990,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",
@@ -14258,21 +14008,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;
                 }
 
@@ -14280,18 +14027,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",
@@ -14303,10 +14047,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;
             }
@@ -14316,10 +14058,6 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def,
 
     ret = 0;
  error:
-    VIR_FREE(port);
-    VIR_FREE(tlsPort);
-    VIR_FREE(autoport);
-    VIR_FREE(defaultMode);
     return ret;
 }
 
@@ -14368,8 +14106,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;
@@ -14418,8 +14156,6 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    VIR_FREE(type);
-
     return def;
 
  error:
@@ -14432,8 +14168,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;
@@ -14446,8 +14182,6 @@ virDomainSoundCodecDefParseXML(xmlNodePtr node)
     }
 
  cleanup:
-    VIR_FREE(type);
-
     return def;
 
  error:
@@ -14463,9 +14197,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;
@@ -14482,7 +14216,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);
@@ -14492,22 +14226,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);
         }
     }
 
@@ -14515,8 +14244,6 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(model);
-
     ctxt->node = save;
     return def;
 
@@ -14532,9 +14259,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;
@@ -14568,9 +14295,6 @@ virDomainWatchdogDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(action);
-    VIR_FREE(model);
-
     return def;
 
  error:
@@ -14586,13 +14310,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;
@@ -14684,10 +14408,6 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(model);
-    VIR_FREE(backend);
-    VIR_FREE(type);
-    VIR_FREE(backends);
     ctxt->node = save;
     return def;
 
@@ -14704,11 +14424,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;
@@ -14755,9 +14475,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPtr xmlopt,
         goto error;
 
  cleanup:
-    VIR_FREE(model);
-    VIR_FREE(deflate);
-
     ctxt->node = save;
     return def;
 
@@ -14793,13 +14510,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;
@@ -14863,7 +14579,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt,
             }
             def->msi.ioeventfd = val;
         }
-        VIR_FREE(tmp);
     }
 
     /* msi option is only relevant with a server */
@@ -14880,7 +14595,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_STEAL_PTR(ret, def);
  cleanup:
     ctxt->node = save;
-    VIR_FREE(tmp);
     virDomainShmemDefFree(def);
     return ret;
 }
@@ -14952,7 +14666,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",
@@ -15013,7 +14727,6 @@ virSysinfoSystemParseXML(xmlNodePtr node,
     ret = 0;
  cleanup:
     virSysinfoSystemDefFree(def);
-    VIR_FREE(tmpUUID);
     return ret;
 }
 
@@ -15023,10 +14736,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;
@@ -15064,8 +14778,6 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt,
     *nbaseBoard = nboards;
     ret = 0;
  cleanup:
-    VIR_FREE(boards);
-    VIR_FREE(nodes);
     ctxt->node = oldnode;
     return ret;
 }
@@ -15077,9 +14789,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)
@@ -15100,7 +14812,6 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctxt,
     VIR_STEAL_PTR(*oem, def);
     ret = 0;
  cleanup:
-    VIR_FREE(strings);
     virSysinfoOEMStringsDefFree(def);
     return ret;
 }
@@ -15156,7 +14867,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",
@@ -15229,7 +14940,6 @@ virSysinfoParseXML(xmlNodePtr node,
     }
 
  cleanup:
-    VIR_FREE(type);
     return def;
 
  error:
@@ -15323,9 +15033,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) {
@@ -15364,8 +15074,6 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node)
     }
 
  cleanup:
-    VIR_FREE(accel2d);
-    VIR_FREE(accel3d);
     return def;
 }
 
@@ -15374,8 +15082,8 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node)
 {
     xmlNodePtr cur;
     virDomainVideoDriverDefPtr def;
-    char *vgaconf = NULL;
     int val;
+    VIR_AUTOFREE(char *) vgaconf = NULL;
 
     cur = node->children;
     while (cur != NULL) {
@@ -15402,7 +15110,6 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node)
     def->vgaconf = val;
 
  cleanup:
-    VIR_FREE(vgaconf);
     return def;
 }
 
@@ -15416,13 +15123,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;
@@ -15529,14 +15236,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:
@@ -15553,8 +15252,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;
 
@@ -15613,8 +15312,6 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    VIR_FREE(type);
-    VIR_FREE(mode);
     ctxt->node = save;
     return def;
 
@@ -15633,7 +15330,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;
@@ -15689,8 +15387,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt,
 
 
  cleanup:
-    VIR_FREE(bus);
-    VIR_FREE(type);
     return def;
 
  error:
@@ -15740,10 +15436,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;
@@ -15815,11 +15513,6 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
     }
 
  cleanup:
-    VIR_FREE(class);
-    VIR_FREE(vendor);
-    VIR_FREE(product);
-    VIR_FREE(version);
-    VIR_FREE(allow);
     return def;
 
  error:
@@ -15834,9 +15527,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;
@@ -15856,13 +15549,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;
 }
@@ -15875,7 +15566,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 {
@@ -15883,10 +15575,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;
 }
@@ -15897,7 +15587,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) {
@@ -15909,7 +15600,6 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
 
     ret = 0;
  cleanup:
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -15918,10 +15608,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"));
@@ -15956,8 +15646,6 @@ virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf,
     ret = 0;
 
  cleanup:
-    VIR_FREE(name);
-    VIR_FREE(enabled);
     return ret;
 }
 
@@ -15967,8 +15655,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;
@@ -15981,7 +15669,6 @@ virDomainPerfDefParseXML(virDomainDefPtr def,
     ret = 0;
 
  cleanup:
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -15991,9 +15678,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:
@@ -16038,7 +15725,6 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
     ret = 0;
 
  cleanup:
-    VIR_FREE(nodemask);
     ctxt->node = save;
     return ret;
 }
@@ -16101,10 +15787,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;
@@ -16154,7 +15840,6 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
     def->session = virXPathString("string(./session)", ctxt);
 
  cleanup:
-    VIR_FREE(type);
     ctxt->node = save;
     return def;
 
@@ -16170,11 +15855,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;
@@ -16214,7 +15899,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
 
         def->discard = val;
     }
-    VIR_FREE(tmp);
 
     /* source */
     if ((node = virXPathNode("./source", ctxt)) &&
@@ -16239,7 +15923,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
     return def;
 
  error:
-    VIR_FREE(tmp);
     virDomainMemoryDefFree(def);
     ctxt->node = save;
     return NULL;
@@ -16250,11 +15933,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;
 
@@ -16315,8 +15999,6 @@ virDomainIOMMUDefParseXML(xmlNodePtr node,
 
  cleanup:
     ctxt->node = save;
-    VIR_FREE(iommu);
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -16327,11 +16009,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;
 
@@ -16380,8 +16063,6 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt,
 
  cleanup:
     ctxt->node = save;
-    VIR_FREE(vsock);
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -17975,17 +17656,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;
 }
 
@@ -17993,12 +17672,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)
@@ -18080,8 +17759,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -18162,7 +17839,7 @@ static virDomainIOThreadIDDefPtr
 virDomainIOThreadIDDefParseXML(xmlNodePtr node)
 {
     virDomainIOThreadIDDefPtr iothrid;
-    char *tmp = NULL;
+    VIR_AUTOFREE(char *) tmp = NULL;
 
     if (VIR_ALLOC(iothrid) < 0)
         return NULL;
@@ -18180,7 +17857,6 @@ virDomainIOThreadIDDefParseXML(xmlNodePtr node)
     }
 
  cleanup:
-    VIR_FREE(tmp);
     return iothrid;
 
  error:
@@ -18195,10 +17871,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) {
@@ -18206,7 +17882,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)
@@ -18232,7 +17907,6 @@ virDomainDefParseIOThreads(virDomainDefPtr def,
         }
         def->iothreadids[def->niothreadids++] = iothrid;
     }
-    VIR_FREE(nodes);
 
     if (virDomainIOThreadIDDefArrayInit(def, iothreads) < 0)
         goto error;
@@ -18240,7 +17914,6 @@ virDomainDefParseIOThreads(virDomainDefPtr def,
     return 0;
 
  error:
-    VIR_FREE(nodes);
     return -1;
 }
 
@@ -18256,8 +17929,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"));
@@ -18301,7 +17974,6 @@ virDomainVcpuPinDefParseXML(virDomainDefPtr def,
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -18317,7 +17989,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"))) {
@@ -18373,7 +18045,6 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node,
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -18386,7 +18057,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"))) {
@@ -18407,7 +18078,6 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node)
     VIR_STEAL_PTR(ret, def);
 
  cleanup:
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -18543,7 +18213,7 @@ virDomainHugepagesParseXML(xmlNodePtr node,
 {
     int ret = -1;
     xmlNodePtr oldnode = ctxt->node;
-    char *nodeset = NULL;
+    VIR_AUTOFREE(char *) nodeset = NULL;
 
     ctxt->node = node;
 
@@ -18571,7 +18241,6 @@ virDomainHugepagesParseXML(xmlNodePtr node,
 
     ret = 0;
  cleanup:
-    VIR_FREE(nodeset);
     ctxt->node = oldnode;
     return ret;
 }
@@ -18648,9 +18317,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");
@@ -18683,9 +18352,6 @@ virDomainLoaderDefParseXML(xmlNodePtr node,
 
     ret = 0;
  cleanup:
-    VIR_FREE(readonly_str);
-    VIR_FREE(secure_str);
-    VIR_FREE(type_str);
     return ret;
 }
 
@@ -18697,8 +18363,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,
@@ -18747,13 +18413,11 @@ virDomainSchedulerParse(xmlNodePtr node,
                            _("Invalid value for element priority"));
             goto error;
         }
-        VIR_FREE(tmp);
     }
 
     return ret;
 
  error:
-    VIR_FREE(tmp);
     virBitmapFree(ret);
     return NULL;
 }
@@ -18836,13 +18500,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;
 
@@ -18976,9 +18640,6 @@ virDomainVcpuParse(virDomainDefPtr def,
     ret = 0;
 
  cleanup:
-    VIR_FREE(nodes);
-    VIR_FREE(tmp);
-
     return ret;
 }
 
@@ -18987,12 +18648,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....
@@ -19123,8 +18784,6 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
     ret = 0;
 
  error:
-    VIR_FREE(nodes);
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -19134,8 +18793,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) {
@@ -19156,7 +18815,6 @@ virDomainResctrlParseVcpus(virDomainDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(vcpus_str);
     return ret;
 }
 
@@ -19196,8 +18854,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;
 
@@ -19242,7 +18900,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
                        tmp);
         goto cleanup;
     }
-    VIR_FREE(tmp);
 
     if (virDomainParseScaledValue("./@size", "./@unit",
                                   ctxt, &size, 1024,
@@ -19255,7 +18912,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
     ret = 0;
  cleanup:
     ctxt->node = oldnode;
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -19328,14 +18984,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;
 
@@ -19423,9 +19079,6 @@ virDomainResctrlMonDefParse(virDomainDefPtr def,
     ret = 0;
  cleanup:
     ctxt->node = oldnode;
-    VIR_FREE(id);
-    VIR_FREE(tmp);
-    VIR_FREE(nodes);
     virDomainResctrlMonDefFree(domresmon);
     return ret;
 }
@@ -19437,10 +19090,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. */
@@ -19478,8 +19131,6 @@ virDomainResctrlNew(xmlNodePtr node,
     VIR_STEAL_PTR(ret, resctrl);
  cleanup:
     virDomainResctrlDefFree(resctrl);
-    VIR_FREE(alloc_id);
-    VIR_FREE(vcpus_str);
     return ret;
 }
 
@@ -19491,13 +19142,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;
 
@@ -19557,7 +19208,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
     ctxt->node = oldnode;
     virDomainResctrlDefFree(resctrl);
     virObjectUnref(alloc);
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -19569,10 +19219,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);
@@ -19643,10 +19293,6 @@ virDomainDefParseCaps(virDomainDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(virttype);
-    VIR_FREE(ostype);
-    VIR_FREE(arch);
-    VIR_FREE(capsdata);
     return ret;
 }
 
@@ -19659,8 +19305,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;
 
@@ -19690,14 +19336,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;
 }
 
@@ -19709,10 +19353,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;
@@ -19771,7 +19415,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
     ctxt->node = oldnode;
     virDomainResctrlDefFree(resctrl);
     virObjectUnref(alloc);
-    VIR_FREE(nodes);
     return ret;
 }
 
@@ -19784,8 +19427,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;
@@ -19795,18 +19437,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()))
@@ -21453,7 +21096,6 @@ virDomainDefParseXML(xmlDocPtr xml,
 
         def->idmap.ngidmap = n;
     }
-    VIR_FREE(nodes);
 
     if ((def->idmap.uidmap && !def->idmap.gidmap) ||
         (!def->idmap.uidmap && def->idmap.gidmap)) {
@@ -21482,7 +21124,6 @@ virDomainDefParseXML(xmlDocPtr xml,
             goto error;
         }
         def->os.smbios_mode = mode;
-        VIR_FREE(tmp);
     }
 
     if (virDomainKeyWrapDefParseXML(def, ctxt) < 0)
@@ -21504,8 +21145,6 @@ virDomainDefParseXML(xmlDocPtr xml,
     return def;
 
  error:
-    VIR_FREE(tmp);
-    VIR_FREE(nodes);
     virDomainDefFree(def);
     return NULL;
 }
@@ -21518,17 +21157,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;
@@ -21554,7 +21193,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);
@@ -21563,10 +21201,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);
@@ -21594,7 +21230,6 @@ virDomainObjParseXML(xmlDocPtr xml,
             virDomainObjTaint(obj, flag);
         }
     }
-    VIR_FREE(nodes);
 
     if (xmlopt->privateData.parse &&
         xmlopt->privateData.parse(ctxt, obj, &xmlopt->config) < 0)
@@ -21615,7 +21250,6 @@ virDomainObjParseXML(xmlDocPtr xml,
 
  error:
     virObjectUnref(obj);
-    VIR_FREE(nodes);
     return NULL;
 }
 
@@ -23152,8 +22786,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,
@@ -23622,8 +23256,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);
@@ -24083,7 +23715,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));
@@ -24095,8 +23727,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))
@@ -26531,8 +26161,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;
@@ -26576,7 +26206,6 @@ virDomainMemorySourceDefFormat(virBufferPtr buf,
     ret = 0;
 
  cleanup:
-    VIR_FREE(bitmap);
     return ret;
 }
 
@@ -27727,7 +27356,7 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDefPtr domresmon,
                                    virResctrlMonitorType tag,
                                    virBufferPtr buf)
 {
-    char *vcpus = NULL;
+    VIR_AUTOFREE(char *) vcpus = NULL;
 
     if (domresmon->tag != tag)
         return 0;
@@ -27745,7 +27374,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDefPtr domresmon,
 
     virBufferAsprintf(buf, "vcpus='%s'/>\n", vcpus);
 
-    VIR_FREE(vcpus);
     return 0;
 }
 
@@ -27756,9 +27384,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,
@@ -27802,7 +27430,6 @@ virDomainCachetuneDefFormat(virBufferPtr buf,
     ret = 0;
  cleanup:
     virBufferFreeAndReset(&childrenBuf);
-    VIR_FREE(vcpus);
     return ret;
 }
 
@@ -27827,8 +27454,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,
@@ -27865,7 +27492,6 @@ virDomainMemorytuneDefFormat(virBufferPtr buf,
     ret = 0;
  cleanup:
     virBufferFreeAndReset(&childrenBuf);
-    VIR_FREE(vcpus);
     return ret;
 }
 
@@ -28000,8 +27626,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'",
@@ -28040,8 +27666,6 @@ virDomainCpuDefFormat(virBufferPtr buf,
     ret = 0;
 
  cleanup:
-    VIR_FREE(cpumask);
-
     return ret;
 }
 
@@ -29246,8 +28870,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;
@@ -29268,7 +28892,6 @@ virDomainSaveXML(const char *configDir,
                          xml);
 
  cleanup:
-    VIR_FREE(configFile);
     return ret;
 }
 
@@ -29278,7 +28901,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;
@@ -29288,7 +28911,6 @@ virDomainSaveConfig(const char *configDir,
 
     ret = 0;
  cleanup:
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -29305,7 +28927,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;
@@ -29315,7 +28937,6 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt,
 
     ret = 0;
  cleanup:
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -29325,8 +28946,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;
@@ -29349,8 +28971,6 @@ virDomainDeleteConfig(const char *configDir,
     ret = 0;
 
  cleanup:
-    VIR_FREE(configFile);
-    VIR_FREE(autostartLink);
     return ret;
 }
 
@@ -29616,7 +29236,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)
@@ -29644,7 +29264,6 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
     ret = 0;
 
  cleanup:
-    VIR_FREE(brokenRaw);
     return ret;
 }
 
@@ -29660,11 +29279,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;
@@ -29675,7 +29294,6 @@ virDomainDefCopy(virDomainDefPtr src,
 
     ret = virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags);
 
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -30103,9 +29721,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:
@@ -30192,7 +29810,6 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
                                   VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
 
  cleanup:
-    VIR_FREE(xmlStr);
     return ret;
 }
 
@@ -30523,8 +30140,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
@@ -30571,7 +30188,6 @@ virDomainDefGetShortName(const virDomainDef *def)
 
     ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname));
  cleanup:
-    VIR_FREE(shortname);
     return ret;
 }
 
@@ -30850,9 +30466,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;
@@ -30919,7 +30535,6 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
 
  cleanup:
     virNetworkDefFree(def);
-    VIR_FREE(xml);
     virObjectUnref(conn);
     virObjectUnref(net);
     return ret;
@@ -31048,10 +30663,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;
@@ -31209,7 +30824,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def)
     virObjectUnref(conn);
     virObjectUnref(pool);
     virObjectUnref(vol);
-    VIR_FREE(poolxml);
     return ret;
 }
 
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux