[Lxml-checkins] r52199 - in lxml/trunk: . src/lxml

scoder at codespeak.net scoder at codespeak.net
Wed Mar 5 22:18:14 CET 2008


Author: scoder
Date: Wed Mar  5 22:18:13 2008
New Revision: 52199

Modified:
   lxml/trunk/   (props changed)
   lxml/trunk/src/lxml/xsltext.pxi
Log:
 r3734 at delle:  sbehnel | 2008-03-05 00:02:01 +0100
 memory leak in .apply_templates() of XSLT extensions


Modified: lxml/trunk/src/lxml/xsltext.pxi
==============================================================================
--- lxml/trunk/src/lxml/xsltext.pxi	(original)
+++ lxml/trunk/src/lxml/xsltext.pxi	Wed Mar  5 22:18:13 2008
@@ -47,19 +47,22 @@
         try:
             while c_node is not NULL:
                 c_next = c_node.next
-                tree.xmlUnlinkNode(c_node)
                 if c_node.type == tree.XML_TEXT_NODE:
-                    python.PyList_Append(results, _collectText(c_node))
+                    python.PyList_Append(
+                        results, funicode(c_node.content))
                 elif c_node.type == tree.XML_ELEMENT_NODE:
                     proxy = _newReadOnlyProxy(
                         context._extension_element_proxy, c_node)
-                    proxy.free_after_use()
                     python.PyList_Append(results, proxy)
+                    # unlink node and make sure it will be freed later on
+                    tree.xmlUnlinkNode(c_node)
+                    proxy.free_after_use()
                 else:
                     raise TypeError("unsupported XSLT result type: %d" %
                                     c_node.type)
                 c_node = c_next
         finally:
+            # free all intermediate nodes that will not be freed by proxies
             tree.xmlFreeNode(c_parent)
         return results
 


More information about the lxml-checkins mailing list