After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 114377 - weird func:result/xsl:variable/exsl:node-set interaction
weird func:result/xsl:variable/exsl:node-set interaction
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.0.25
Other Windows
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2003-06-04 02:25 UTC by Brett Kail
Modified: 2006-07-14 16:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
delay free'ing of xsl:variable's when inside func:function's (4.45 KB, patch)
2004-03-04 22:52 UTC, Brett Kail
none Details | Review

Description Brett Kail 2003-06-04 02:25:37 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)/*"/>).
Comment 1 Daniel Veillard 2003-06-09 12:54:10 UTC
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
Comment 2 Brett Kail 2004-03-04 22:52:45 UTC
Created attachment 25178 [details] [review]
delay free'ing of xsl:variable's when inside func:function's
Comment 3 kbuchcik 2006-07-14 16:31:14 UTC
Fixed in CVS HEAD now.

Thanks for the report!