From: John Ferlan Date: Mon, 20 Feb 2017 12:19:10 +0000 (-0500) Subject: conf: Fix leak in virNodeDeviceDefParseXML X-Git-Tag: v3.1.0-rc2^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca1f38545750d597c75c9773723c716483b03e5c;p=thirdparty%2Flibvirt.git conf: Fix leak in virNodeDeviceDefParseXML The 'nodes' is overwritten after the first usage and possibly leaked if any code in the first set of parsing goes to error. Found by Coverity. Signed-off-by: John Ferlan --- diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index c80284017d..43e23fc0c1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1766,7 +1766,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, { virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; - xmlNodePtr *nodes; + xmlNodePtr *nodes = NULL; int n, m; size_t i; @@ -1789,7 +1789,6 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, def->sysfs_path = virXPathString("string(./path[1])", ctxt); /* Parse devnodes */ - nodes = NULL; if ((n = virXPathNodeSet("./devnode", ctxt, &nodes)) < 0) goto error; @@ -1842,7 +1841,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ctxt); /* Parse device capabilities */ - nodes = NULL; + VIR_FREE(nodes); if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto error; @@ -1859,10 +1858,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, nodes[i], create, virt_type); - if (!*next_cap) { - VIR_FREE(nodes); + if (!*next_cap) goto error; - } next_cap = &(*next_cap)->next; } @@ -1872,6 +1869,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, error: virNodeDeviceDefFree(def); + VIR_FREE(nodes); return NULL; }