Hello
our customer showed a very significant memory leak in xml2.
try to
select xpath_number('<data>' || generate_series || '</data>','/data')
from generate_series(1,500000);
attention! take all memory very fast
It never release a memory allocated for context and doctree.
Regards
Pavel Stehule
*** ./xpath.c.orig 2010-03-03 20:10:29.000000000 +0100
--- ./xpath.c 2010-11-26 09:50:42.492451256 +0100
***************
*** 53,58 ****
--- 53,61 ----
static xmlXPathObjectPtr pgxml_xpath(text *document, xmlChar *xpath);
+ /* should be global, to be realeased */
+ static xmlDocPtr doctree;
+ static xmlXPathContextPtr ctxt;
/*
* Initialize for xml parsing.
***************
*** 238,243 ****
--- 241,250 ----
if (xpres == NULL)
PG_RETURN_NULL();
+
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doctree);
+
PG_RETURN_TEXT_P(xpres);
}
***************
*** 272,277 ****
--- 279,288 ----
if (xpres == NULL)
PG_RETURN_NULL();
+
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doctree);
+
PG_RETURN_TEXT_P(xpres);
}
***************
*** 310,315 ****
--- 321,330 ----
if (xpres == NULL)
PG_RETURN_NULL();
+
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doctree);
+
PG_RETURN_TEXT_P(xpres);
}
***************
*** 341,346 ****
--- 356,365 ----
fRes = xmlXPathCastToNumber(res);
+ /* release a used context and document */
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doctree);
+
if (xmlXPathIsNaN(fRes))
PG_RETURN_NULL();
***************
*** 375,380 ****
--- 394,402 ----
bRes = xmlXPathCastToBoolean(res);
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(doctree);
+
PG_RETURN_BOOL(bRes);
}
***************
*** 385,392 ****
static xmlXPathObjectPtr
pgxml_xpath(text *document, xmlChar *xpath)
{
- xmlDocPtr doctree;
- xmlXPathContextPtr ctxt;
xmlXPathObjectPtr res;
xmlXPathCompExprPtr comppath;
int32 docsize;
--- 407,412 ----
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers