Shlomi Fish avatar Shlomi Fish committed a855cfb

Fixed "XPathContext memory leak on registerFunction."

- Fixed https://rt.cpan.org/Ticket/Display.html?id=83744
- XPathContext memory leak on registerFunction.
- Thanks to DGINEV for the report and Yuriy for the patch.

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+    - Fixed https://rt.cpan.org/Ticket/Display.html?id=83744
+        - XPathContext memory leak on registerFunction.
+        - Thanks to DGINEV for the report and Yuriy for the patch.
+
 2.0101          Thu 15 Aug 08:29:15 IDT 2013
     - Fixed https://rt.cpan.org/Ticket/Display.html?id=87089 .
         - "HTML doctype differs for string/scalar input"
                 || SvPOK(func)))) {
             if (ctxt->funcLookupData == NULL) {
                 if (SvOK(func)) {
-                    pfdr = newRV_inc((SV*) newHV());
+                    pfdr = newRV_noinc((SV*) newHV());
                     ctxt->funcLookupData = pfdr;
                 } else {
                     /* looks like no perl function was never registered, */
 t/47load_xml_callbacks.t
 t/48_rt55000.t
 t/48importing_nodes_IDs_rt_69520.t
+t/48_memleak_rt_83744.t
 t/48_removeChild_crashes_rt_80395.t
 t/49_load_html.t
 t/49callbacks_returning_undef.t

t/48_memleak_rt_83744.t

+
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+
+XPathContext memory leak on registerFunction.
+
+See L<https://rt.cpan.org/Ticket/Display.html?id=83744>.
+
+=cut
+
+use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace };
+use Test::More HAS_LEAKTRACE ? (tests => 2) : (skip_all => 'Test::LeakTrace is required for memory leak tests.');
+use Test::LeakTrace;
+
+# TEST
+no_leaks_ok {
+    use XML::LibXML::XPathContext;
+} 'load XPathContext without leaks';
+
+# TEST
+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';
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.