You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I'm using a custom XPath function and I raise an exception within my handler, memory is leaked.
Help us reproduce what you're seeing
Run this script and watch the process's memory utilization grow:
#! /usr/bin/env rubyrequire'nokogiri'loopdodoc=Nokogiri::XML.parse("<foo></foo>")begindoc.xpath('//foo[exceptional()]',Class.new{defexceptional()raise"ONOES"end}.new)exit1# should never be reachedrescue=>eputseendend
I discovered this while working on #1610. It's not clear to me yet (I haven't taken the time to look) whether libxml2 is leaking this memory or if it's something in Ruby-space; but I suspect it's libxml2 not being able to clean up the XPath context because we've longjmped over it.
In which case, we may need to do something more invasive to wrap the calls back into Ruby space in a rescue block.
I'd also be curious to see if the following functionality is also susceptible to the same class of issue (raising an exception from a Ruby callback):
SAX parsing callbacks
XSLT registered transformation functions
The text was updated successfully, but these errors were encountered:
I'd also be curious to see if the following functionality is also susceptible to the same class of issue (raising an exception from a Ruby callback):
SAX parsing callbacks
Yep, as part of my work on #3265, I discovered that raising from a callback like SAX::Document#characters will leak (because the C code needs to free that string!).
flavorjones
changed the title
[bug] Memory is leaked when raising an exception from a custom XPath handler
[bug] Memory is leaked when raising an exception from a custom XPath function, or from some SAX handler callbacks
Jul 1, 2024
Please describe the bug
If I'm using a custom XPath function and I raise an exception within my handler, memory is leaked.
Help us reproduce what you're seeing
Run this script and watch the process's memory utilization grow:
Expected behavior
Memory shouldn't be leaking.
Environment
Additional context
I discovered this while working on #1610. It's not clear to me yet (I haven't taken the time to look) whether libxml2 is leaking this memory or if it's something in Ruby-space; but I suspect it's libxml2 not being able to clean up the XPath context because we've longjmped over it.
In which case, we may need to do something more invasive to wrap the calls back into Ruby space in a rescue block.
I'd also be curious to see if the following functionality is also susceptible to the same class of issue (raising an exception from a Ruby callback):
The text was updated successfully, but these errors were encountered: