GNOME Bugzilla – Bug 436324
memory leak in exsltMathConstantFunction()
Last modified: 2007-05-06 16:04:26 UTC
For the following stylesheet, I get a memory loss report under valgrind: ----------------------- <xsl:stylesheet version="1.0" xmlns:math="http://exslt.org/math" xmlns:str="http://exslt.org/strings" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="math str xsl"> <xsl:template match="text()"> <xsl:value-of select="str:align(string(.), '---', 'center')" /> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:attribute name="pi"> <xsl:value-of select="math:constant('PI', count(*)+2)"/> </xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> ----------------------- Note the use of the "PI" constant. This is the report: ----------------------- ==12768== 20 bytes in 6 blocks are definitely lost in loss record 7 of 78 ==12768== at 0x4021620: malloc (vg_replace_malloc.c:149) ==12768== by 0x47D9E05: xmlStrndup (xmlstring.c:45) ==12768== by 0x47D9F74: xmlStrsub (xmlstring.c:409) ==12768== by 0x47379AD: exsltMathConstantFunction (math.c:443) ==12768== by 0x47BE581: xmlXPathCompOpEval (xpath.c:13336) ==12768== by 0x47BE00A: xmlXPathCompOpEval (xpath.c:13719) ==12768== by 0x47BFDCF: xmlXPathRunEval (xpath.c:14287) ==12768== by 0x47C4205: xmlXPathCompiledEvalInternal (xpath.c:14645) ==12768== by 0x47C4411: xmlXPathCompiledEval (xpath.c:14709) ==12768== by 0x4726A1A: xsltValueOf (transform.c:4396) ==12768== by 0x4723AE6: xsltApplySequenceConstructor (transform.c:2580) ==12768== by 0x4712AB7: xsltEvalTemplateString (templates.c:225) ----------------------- I suspect the problem to be the math constant name (retrieved via xmlXPathPopString), which is not freed.
I found two separate places in math.c where leaks were occurring and fixed them. Fixed code (libexslt/math.c) is in SVN. It certainly cures your test case. I'm closing the bug, but please re-open it (or open a new one) if you find any more. Thanks for the report.