From: tv@fuzzy.cz
To: pgsql-bugs@postgresql.org
Subject: memory leak in xml2 contrib module
Date: Fri, 26 Nov 2010 13:54:19 +0100
Message-ID: <d7a03755ddcb11e5ffca891bbf7aa33d.squirrel@sq.gransy.com> (raw)
Hi,
one of my colleagues found ugly memory leak in the xml2 contrib module.
Try this:
select xpath_number('<data>' || generate_series || '</data>','/data') from
generate_series(1,500000);
This will allocate arbitrary amount of memory, and it won't release it
until the backend exits (user disconnects). We've found this in 8.4 and
I've verified it's still present in 9.0.1.
I know the xml2 module is deprecated and most of the functions was moved
into core (and behave correctly) but xslt_process function was not and
that's why xml2 module is used.
Pavel Stehule already prepared a fix (see the attachment).
regards
Tomas
Attachments:xml2memleakfix.diff (text/plain, 1.6K) download
*** ./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 ----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tv@fuzzy.cz
Subject: Re: memory leak in xml2 contrib module
In-Reply-To: <d7a03755ddcb11e5ffca891bbf7aa33d.squirrel@sq.gransy.com>
References: <d7a03755ddcb11e5ffca891bbf7aa33d.squirrel@sq.gransy.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox