Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two memory leaks with custom XSLT function arguments #504

Merged
merged 1 commit into from Nov 23, 2011

Conversation

ender672
Copy link
Member

@ender672 ender672 commented Aug 1, 2011

Nokogiri was not freeing an array and was not freeing a libxml
XPath object.

Nokogiri was not freeing an array and was not freeing a libxml
XPath object.
@ender672
Copy link
Member Author

ender672 commented Aug 1, 2011

Here is a script that demonstrates the memory leak:

require 'nokogiri'
include Nokogiri

foo = Class.new do
  def capitalize nodes
    nodes.first.content.upcase
  end
end

XSLT.register "http://e.org/functions", foo

xml = Nokogiri.XML(<<-EOXML)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
 "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="Content-type" content="application/xhtml+xml"/>
    <title>Foo</title>
  </head>
  <body>
    <h1>Foo</h1>
    <p>Lorem ipsum.</p>
  </body>
</html>
EOXML

xsl = Nokogiri.XSLT(<<-EOXSL)
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:f="http://e.org/functions"
  extension-element-prefixes="f">

  <xsl:template match="text()">
    <xsl:copy-of select="f:capitalize(.)"/>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:apply-imports/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
EOXSL

loop do
  xsl.transform xml
end

ender672 added a commit that referenced this pull request Nov 23, 2011
Fix two memory leaks with custom XSLT function arguments
@ender672 ender672 merged commit 328af93 into sparklemotion:master Nov 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant