Skip site navigation (1) Skip section navigation (2)

Re: BUG #3860: xpath crashes backend when is querying xmlagg result

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Sokolov Yura <funny(dot)falcon(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>, Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: BUG #3860: xpath crashes backend when is querying xmlagg result
Date: 2008-01-11 00:23:06
Message-ID: 12875.1200010986@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-patches
Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> + void
> + AtEOXact_xml(void)
> + {
> + 	if (LibxmlContext == NULL)
> + 		return;
> + 
> + 	MemoryContextDelete(LibxmlContext);
> + 	LibxmlContext = NULL;
> + 
> + 	xmlCleanupParser();
> + }

[ blink... ]  Shouldn't that be the other way around?  It looks to me
like xmlCleanupParser will be pfree'ing already-deleted data.  Did you
test this with CLOBBER_FREED_MEMORY active?

Also, I don't see how this patch fixes what I believe to be the
fundamental problem, which is that we have code paths that invoke
libxml without having previously initialized the alloc support.
I think the sequence

	if (LibxmlContext == NULL)
	{
		create LibxmlContext;
		xmlMemSetup(...);
	}

ought to be executed before *any* use of libxml stuff (which suggests
factoring it out as a subroutine...)

We also need to do some testing to see if letting the thing go until
transaction end is OK, or whether we will see unacceptable memory leaks
over long series of XML calls.  (In particular I suspect that we'd
better zap the context at subtransaction abort; but even without any
error, are we sure that normal operations don't leak memory?)

One thing I was wondering about earlier today is whether libxml isn't
expecting NULL-return-on-failure from the malloc-substitute routine.
If we take control away from it unexpectedly, I wouldn't be a bit
surprised if its data structures are left corrupt.  This might lead to
failures during cleanup.

I do like the idea of getting rid of the PG_TRY blocks and the
associated cleanup attempts; with the approach you're converging on
here, we need only assume that xmlCleanupParser() will get rid of
all staticly-allocated pointers and not crash, whereas right now we
are assuming a great deal of libxml stuff still works after an ereport
(which makes throwing ereport from xml_palloc even more risky).

			regards, tom lane

In response to

Responses

pgsql-bugs by date

Next:From: Alvaro HerreraDate: 2008-01-11 03:41:40
Subject: Re: BUG #3860: xpath crashes backend when is queryingxmlagg result
Previous:From: Tom LaneDate: 2008-01-10 22:00:02
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins

pgsql-patches by date

Next:From: Alvaro HerreraDate: 2008-01-11 03:41:40
Subject: Re: BUG #3860: xpath crashes backend when is queryingxmlagg result
Previous:From: Alvaro HerreraDate: 2008-01-10 21:16:40
Subject: Re: BUG #3860: xpath crashes backend when is queryingxmlagg result

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group