Re: DETOASTing in custom memory context

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: strk <strk(at)keybit(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: DETOASTing in custom memory context
Date: 2003-10-27 19:13:11
Message-ID: 2043.1067281991@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

strk <strk(at)keybit(dot)net> writes:
>> From whitin an aggregate sfunc I did:
> oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
> geom = (GEOMETRY *)PG_DETOAST_DATUM(datum);
> MemoryContextSwitchTo(oldcontext);

> And later in aggregate's finalfunc:
> pfree(geom);

> Result:
> segfault!

> What's wrong with it ?

Perhaps you wanted PG_DETOAST_DATUM_COPY(). Or possibly use
PG_FREE_IF_COPY() rather than an unconditional pfree, though
that would depend on just what your usage pattern is.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2003-10-27 19:20:35 Re: Vacuum thoughts
Previous Message Andrew Dunstan 2003-10-27 19:03:39 Re: pg_ctl reports succes when start fails