Fix possible memory leak in util/virxml.c

A "xmlstr" string may not be assigned into a "doc" pointer and it
could cause memory leak. To fix it if the "doc" pointer is NULL and
the "xmlstr" string is not assigned we should free it.

This has been found by coverity.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2014-01-13 15:06:03 +01:00
parent 788e6cb25b
commit 67fbf129fc
1 changed files with 2 additions and 0 deletions

View File

@ -1047,6 +1047,8 @@ virXMLExtractNamespaceXML(xmlNodePtr root,
cleanup: cleanup:
if (doc) if (doc)
*doc = xmlstr; *doc = xmlstr;
else
VIR_FREE(xmlstr);
xmlFreeNode(nodeCopy); xmlFreeNode(nodeCopy);
return ret; return ret;
} }