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

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sokolov Yura <funny(dot)falcon(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: BUG #3860: xpath crashes backend when is querying xmlagg result
Date: 2008-01-09 18:07:38
Message-ID: 20080109180738.GK4651@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches

Tom Lane escribió:
> Alvaro Herrera <alvherre(at)commandprompt(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Oleg Kharin 2008-01-09 18:07:55 BUG #3865: ERROR: failed to build any 8-way joins
Previous Message Alvaro Herrera 2008-01-09 17:59:48 Re: BUG #3858: psql hangs if called as postgres is coming online

Browse pgsql-patches by date

  From Date Subject
Next Message Gregory Stark 2008-01-09 19:05:07 Re: OUTER JOIN performance regression remains in 8.3beta4
Previous Message Tom Lane 2008-01-09 17:38:30 Re: BUG #3860: xpath crashes backend when is querying xmlagg result