[xmlsec] memory leak in xmlSecReplaceContent
Aleksey Sanin
aleksey at aleksey.com
Thu Jun 17 11:20:04 PDT 2004
Hi, Tomas!
After looking at the code I remembered that the xmlSecReplaceContent()
function used the "dummy" node to workaround some problems with
replacing a node in LibXML2. It was almost two years ago and now
there is no need to do this. The attached patch greatly simplifies
this function and fixes the memory leak. It is checked in CVS as well:
Checking in ChangeLog;
/cvs/gnome/xmlsec/ChangeLog,v <-- ChangeLog
new revision: 1.206; previous revision: 1.205
done
Checking in src/xmlenc.c;
/cvs/gnome/xmlsec/src/xmlenc.c,v <-- xmlenc.c
new revision: 1.67; previous revision: 1.66
done
Checking in src/xmltree.c;
/cvs/gnome/xmlsec/src/xmltree.c,v <-- xmltree.c
new revision: 1.38; previous revision: 1.37
done
Thanks for reporting the bug!
Aleksey
-------------- next part --------------
Index: src/xmlenc.c
===================================================================
RCS file: /cvs/gnome/xmlsec/src/xmlenc.c,v
retrieving revision 1.66
diff -u -r1.66 xmlenc.c
--- src/xmlenc.c 21 Jul 2003 03:12:48 -0000 1.66
+++ src/xmlenc.c 17 Jun 2004 18:15:14 -0000
@@ -461,7 +461,7 @@
return(-1);
}
encCtx->resultReplaced = 1;
- } else if(xmlStrEqual(encCtx->type, xmlSecTypeEncContent)) {
+ } else if((encCtx->type != NULL) && xmlStrEqual(encCtx->type, xmlSecTypeEncContent)) {
ret = xmlSecReplaceContent(node, tmpl);
if(ret < 0) {
xmlSecError(XMLSEC_ERRORS_HERE,
Index: src/xmltree.c
===================================================================
RCS file: /cvs/gnome/xmlsec/src/xmltree.c,v
retrieving revision 1.37
diff -u -r1.37 xmltree.c
--- src/xmltree.c 24 Feb 2004 20:11:30 -0000 1.37
+++ src/xmltree.c 17 Jun 2004 18:15:15 -0000
@@ -460,40 +460,15 @@
*/
int
xmlSecReplaceContent(xmlNodePtr node, xmlNodePtr newNode) {
- xmlNodePtr dummy;
- xmlNodePtr ptr;
-
xmlSecAssert2(node != NULL, -1);
xmlSecAssert2(newNode != NULL, -1);
-
- dummy = xmlNewDocNode(newNode->doc, NULL, BAD_CAST "dummy", NULL);
- if(dummy == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlNewDocNode",
- XMLSEC_ERRORS_R_XML_FAILED,
- "node=dummy");
- return(-1);
- }
-
- if(newNode == xmlDocGetRootElement(newNode->doc)) {
- ptr = xmlDocSetRootElement(newNode->doc, dummy);
- } else {
- ptr = xmlReplaceNode(newNode, dummy);
- }
- if(ptr == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlDocSetRootElement or xmlReplaceNode",
- XMLSEC_ERRORS_R_XML_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
- xmlFreeNode(dummy);
- return(-1);
- }
-
+
+ xmlUnlinkNode(newNode);
+ xmlSetTreeDoc(newNode, node->doc);
xmlNodeSetContent(node, NULL);
- xmlAddChild(node, ptr);
- xmlSetTreeDoc(ptr, node->doc);
+ xmlAddChild(node, newNode);
+ xmlSetTreeDoc(newNode, node->doc);
+
return(0);
}
More information about the xmlsec
mailing list