pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedmemory leak in xml2 contrib module
3+ messages / 3 participants
[nested] [flat]
* memory leak in xml2 contrib module
@ 2010-11-26 12:54 tv@fuzzy.cz
0 siblings, 1 reply; 3+ messages in thread
From: tv@fuzzy.cz @ 2010-11-26 12:54 UTC (permalink / raw)
To: pgsql-bugs
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 ----
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: memory leak in xml2 contrib module
@ 2010-12-14 20:50 Robert Haas <robertmhaas@gmail.com>
parent: tv@fuzzy.cz
0 siblings, 1 reply; 3+ messages in thread
From: Robert Haas @ 2010-12-14 20:50 UTC (permalink / raw)
To: tv@fuzzy.cz; +Cc: pgsql-bugs
On Fri, Nov 26, 2010 at 7:54 AM, <tv@fuzzy.cz> wrote:
> 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).
I don't see a response to this email, but it looks like Tom did apply a fix.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: memory leak in xml2 contrib module
@ 2010-12-14 20:57 Tomas Vondra <tv@fuzzy.cz>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Tomas Vondra @ 2010-12-14 20:57 UTC (permalink / raw)
To: pgsql-bugs
Dne 14.12.2010 21:50, Robert Haas napsal(a):
> On Fri, Nov 26, 2010 at 7:54 AM, <tv@fuzzy.cz> wrote:
>> 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).
>
> I don't see a response to this email, but it looks like Tom did apply a fix.
Yes, AFAIK there's a relevant discussion in the pgsql-hackers list.
regards
Tomas
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2010-12-14 20:57 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-11-26 12:54 memory leak in xml2 contrib module tv@fuzzy.cz
2010-12-14 20:50 ` Robert Haas <robertmhaas@gmail.com>
2010-12-14 20:57 ` Tomas Vondra <tv@fuzzy.cz>
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