Re: DETOASTing in custom memory context

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

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 ?

NOTE that if I MemoryContextAllocate in fcinfo->flinfo->fn_mcxt and
memcopy DETOASTED geom, everything works (ar at least it seems to)

--strk;

strk wrote:
> Tom, thanks again for the quick answer and
> sorry for the lame question about memor allocation.
>
> I hope this is acceptable:
> Is there a way to make PG_DETOAST_DATUM and friends allocate
> memory in a custom memory context ?
>
> Right now I'm DETOASTing, memcopying in a custom context
> and pfreeing the DETOASTed datum, I'd like to avoid one
> copy.
>
> TIA.
> --strk;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2003-10-27 19:03:39 Re: pg_ctl reports succes when start fails
Previous Message Tom Lane 2003-10-27 18:10:45 Re: Timestamp docs weirdness