GNOME Bugzilla – Bug 114377
weird func:result/xsl:variable/exsl:node-set interaction
Last modified: 2006-07-14 16:31:14 UTC
[This should be for v1.0.30, but that is not currently an option] Below is a reduced testcase of what I was trying to accomplish with <func:result/>: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:func="http://exslt.org/functions" xmlns:my="http://www.xontech.com/functions" extension-element-prefixes="func"> <func:function name="my:check"> <xsl:variable name="test"> <node/> </xsl:variable> <xsl:variable name="test-node" select="exsl:node-set ($test)/*"/> <func:result select="$test-node"/> </func:function> <xsl:template match="/"> <xsl:copy-of select="my:check()"/> </xsl:template> </xsl:stylesheet> I ran it with 'xsltproc test.xslt test.xslt' and the result is a very strange element name and namespace that appear to come from invalid memory reads. Using libxml 20507, libxslt 10030 and libexslt 720 xsltproc was compiled against libxml 20507, libxslt 10030 and libexslt 720 libxslt 10030 was compiled against libxml 20507 libexslt 720 was compiled against libxml 20507 In an attempt to further reduce the testcase, I just noticed the removing the extra step with the second <xsl:variable/> in my:check() seems to work fine (i.e. <func:result select="exsl:node-set($test)/*"/>).
All the variables created in func:function are deallocated upon exit. As a result the subtree for test-node is deallocated and the returned value is a stale link to this freed tree, resulting to a crash when accessed later. This is gonna be a PITA to fix, C is not a garbage collected language and all those extensions are simply making memory management at the implementation a real hell. You found a workaround, use it, I may fix this at some point but it's far from simple I don't have found a good way to hamdle the fact that func:function breaks the rules of scoping for XSLT variables. Daniel
Created attachment 25178 [details] [review] delay free'ing of xsl:variable's when inside func:function's
Fixed in CVS HEAD now. Thanks for the report!