Subject: | register_function-s are leaking memory when return value is nodelist |
Hi Petr,
see attached file for an example that is possible to run and that will
eat memory. It is enough to replace 'return $nl;' by 'return "";' in the
anonymous sub and the memory usage is stable.
Regards,
Jozef
Subject: | register_function-nodelist-mem.pl |
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::LibXSLT;
exit main ();
sub main {
my $xsl_dom = XML::LibXML->load_xml(
string => << '__END_XSL__'
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mem="urn:memTest">
<xsl:template match="/">
Nodes are: <xsl:copy-of select="mem:someNodes()"/>
</xsl:template>
</xsl:stylesheet>
__END_XSL__
);
my $xml_dom = XML::LibXML->load_xml(
string => << '__END_XML__'
<rootElement/>
__END_XML__
);
my $xsl = XML::LibXSLT->new->parse_stylesheet($xsl_dom);
XML::LibXSLT->register_function(
'urn:memTest',
'someNodes',
sub {
my $nl = XML::LibXML::NodeList->new;
$nl->push(XML::LibXML::Text->new('text'));
return $nl;
}
);
while (1) {
$xsl->transform($xml_dom);
}
exit 0;
}