Re: DETOASTing in custom memory context - Mailing list pgsql-hackers

From Tom Lane
Subject Re: DETOASTing in custom memory context
Date
Msg-id 2043.1067281991@sss.pgh.pa.us
Whole thread Raw
In response to Re: DETOASTing in custom memory context  (strk <strk@keybit.net>)
Responses Re: DETOASTing in custom memory context  (strk <strk@keybit.net>)
List pgsql-hackers
strk <strk@keybit.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


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: pg_ctl reports succes when start fails
Next
From: Jan Wieck
Date:
Subject: Re: Vacuum thoughts