Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > Re: Problem ret...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 9350 of 9928
Post > Topic >>

Re: Problem returning strings with pgsql 8.3.x

by tgl@[EMAIL PROTECTED] (Tom Lane) May 13, 2008 at 10:01 AM

Martijn van Oosterhout <kleptog@[EMAIL PROTECTED]
> writes:
> On Mon, May 12, 2008 at 11:23:17PM -0600, Josh Tolley wrote:
>> SPI_push();
>> retval =
>> InputFunctionCall(&flinfo, lolVarGetString(returnVal, true),
>> resultTypeIOParam, -1);
>> SPI_pop();

> Won't this cause the return value to be allocated inside a new memory
> block which gets freeds at the SPI_pop?

The SPI_pop in itself is harmless ... the problem is the SPI_finish
further down, which will release all simple palloc's done within the
SPI function context.  What he needs is something comparable to this bit
in plpgsql:

            /*
             * If the function's return type isn't by value, copy the
value
             * into upper executor memory context.
             */
            if (!fcinfo->isnull && !func->fn_retbyval)
            {
                Size        len;
                void       *tmp;

                len = datumGetSize(estate.retval, false,
func->fn_rettyplen);
                tmp = SPI_palloc(len);
                memcpy(tmp, DatumGetPointer(estate.retval), len);
                estate.retval = PointerGetDatum(tmp);
            }

ie, push the data into something allocated with SPI_palloc().

I would bet large amounts of money that the problem is not "new in
8.3.0", either.  Perhaps Josh was not testing in an --enable-cassert
(CLOBBER_FREED_MEMORY) build before.

			regards, tom lane

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
 




 3 Posts in Topic:
Problem returning strings with pgsql 8.3.x
eggyknap@[EMAIL PROTECTED  2008-05-12 23:23:17 
Re: Problem returning strings with pgsql 8.3.x
kleptog@[EMAIL PROTECTED]  2008-05-13 08:33:01 
Re: Problem returning strings with pgsql 8.3.x
tgl@[EMAIL PROTECTED] (T  2008-05-13 10:01:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Aug 21 18:34:52 CDT 2008.