Subject: | XPathContext memory leak on registerFunction |
I am using the following test:
########################
########################
use Test::Builder;
my $Test=Test::Builder->new();
$Test->expected_tests(2);
use Test::LeakTrace;
no_leaks_ok {
use XML::LibXML::XPathContext;
} ' load XPathContext without leaks ';
no_leaks_ok {
my $context = XML::LibXML::XPathContext->new();
$context->registerFunction('match-font',sub{1;});
$context->unregisterFunction('match-font');
} ' register an XPath function and unregister it, without leaks '
########################
########################
There is a memory leak here, that occurs only after registerFunction has
been called. From what I traced, registerFunctionNS, in the native C
library uses xmlHashCreate to allocate a new hash in the hashFunc field
of the context.
Looking at the current XS code at:
http://cpansearch.perl.org/src/SHLOMIF/XML-LibXML-2.0014/LibXML.xs
the DESTROY method of XPathContext is not freeing any of the function
datastructures (allocated via registerFunctionNS and friends).
It would be quite nice to get a patch here.