Re: BUG #3860: xpath crashes backend when is querying xmlagg result - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: BUG #3860: xpath crashes backend when is querying xmlagg result
Date
Msg-id 20080109180738.GK4651@alvh.no-ip.org
Whole thread Raw
In response to Re: BUG #3860: xpath crashes backend when is querying xmlagg result  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #3860: xpath crashes backend when is querying xmlagg result
List pgsql-bugs
Tom Lane escribió:
> Alvaro Herrera <alvherre@commandprompt.com> writes:
> > What's happening is that libxml encoding handler table is being
> > allocated in an ExprContext which apparently is too short-lived.
>
> > I'm not seeing very well how to handle this -- one idea would be to
> > manually call xmlInitCharEncodingHandlers (which is public but supposed
> > to be called internally by libxml) with a longer-lived context, but I
> > wonder whether there's some other initialization that will come bite us.
>
> Ugh.  This seems like about the worst-case scenario: we don't know when
> libxml chooses to allocate or free this data structure, and apparently
> we have no way to force it to be freed.

Yeah, we can free it with xmlCleanupParser.  Too blunt an instrument,
perhaps?

> > Another idea would be to initialize and then destroy the libxml state
> > separately for each expression, which perhaps doesn't really work at
> > all.
>
> That's what we're trying to do now, I thought.

Yeah, apparently it doesn't work very well.

> I actually don't see a problem with letting it use malloc for stuff that
> it is going to manage for itself.  I guess the problem comes with
> transient return values of libxml functions; we'd want to explicitly
> move those into palloc-based storage and then free() them.

I guess the problem is that the objects can contain pointers and we have
no way of following those to copy them.  Perhaps we can make it use
malloc, let it create the object, switch to palloc, create a clone,
revert to malloc, free the original.

What problem you have with it having its own memory context?  I don't
think it has any particular disadvantage.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: BUG #3858: psql hangs if called as postgres is coming online
Next
From: "Oleg Kharin"
Date:
Subject: BUG #3865: ERROR: failed to build any 8-way joins