提交 ca1f3854 编写于 作者: J John Ferlan

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: NJohn Ferlan <jferlan@redhat.com>
上级 38a8489c
...@@ -1766,7 +1766,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1766,7 +1766,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
{ {
virNodeDeviceDefPtr def; virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr *next_cap; virNodeDevCapsDefPtr *next_cap;
xmlNodePtr *nodes; xmlNodePtr *nodes = NULL;
int n, m; int n, m;
size_t i; size_t i;
...@@ -1789,7 +1789,6 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1789,7 +1789,6 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
def->sysfs_path = virXPathString("string(./path[1])", ctxt); def->sysfs_path = virXPathString("string(./path[1])", ctxt);
/* Parse devnodes */ /* Parse devnodes */
nodes = NULL;
if ((n = virXPathNodeSet("./devnode", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./devnode", ctxt, &nodes)) < 0)
goto error; goto error;
...@@ -1842,7 +1841,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1842,7 +1841,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
ctxt); ctxt);
/* Parse device capabilities */ /* Parse device capabilities */
nodes = NULL; VIR_FREE(nodes);
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
goto error; goto error;
...@@ -1859,10 +1858,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1859,10 +1858,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
nodes[i], nodes[i],
create, create,
virt_type); virt_type);
if (!*next_cap) { if (!*next_cap)
VIR_FREE(nodes);
goto error; goto error;
}
next_cap = &(*next_cap)->next; next_cap = &(*next_cap)->next;
} }
...@@ -1872,6 +1869,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1872,6 +1869,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
error: error:
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
VIR_FREE(nodes);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册