]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virxml: Fix possible memory leak in virXMLNodeContentString()
authorKristina Hanicova <khanicov@redhat.com>
Wed, 17 Mar 2021 16:43:19 +0000 (17:43 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Mar 2021 11:45:05 +0000 (12:45 +0100)
Previously, if xml node passed to the virXMLNodeContentString()
was not of type XML_ELEMENT_NODE, @ret could have caused a memory
leak because xmlNodeGetContent() works for other types of nodes
as well.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virxml.c

index 060b7530fc2bdf520b0c3d1ea0200079c51c00df..4a6fe09468418e4a17afae82a3e3fa6ede0fa0cb 100644 (file)
@@ -536,7 +536,7 @@ virXMLPropStringLimit(xmlNodePtr node,
 char *
 virXMLNodeContentString(xmlNodePtr node)
 {
-    char *ret = (char *)xmlNodeGetContent(node);
+    char *ret = NULL;
 
     if (node->type !=  XML_ELEMENT_NODE) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -545,6 +545,8 @@ virXMLNodeContentString(xmlNodePtr node)
         return NULL;
     }
 
+    ret = (char *)xmlNodeGetContent(node);
+
     if (!ret) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("node '%s' has unexpected NULL content. This could be caused by malformed input, or a memory allocation failure"),