Custom C function - is palloc broken? - Mailing list pgsql-general

From Nathan Thatcher
Subject Custom C function - is palloc broken?
Date
Msg-id d9c17fb40805032039r29d75ac1i53addc025cdb0bc2@mail.gmail.com
Whole thread Raw
Responses Re: Custom C function - is palloc broken?  (Craig Ringer <craig@postnewspapers.com.au>)
Re: Custom C function - is palloc broken?  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-general
First off, I am developing custom c functions for PostgreSQL 8.3 in
Windows (sorry... not my choice). It appears that there is some
underlying problem in the server that is causing a runtime error to
crash the server when I use palloc. For example... I run the
following:

PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
    int32        arg = PG_GETARG_INT32(0);
    PG_RETURN_INT32(arg + 1);
}

and it works just fine. NOTE: this is directly from the tutorial
directory. Now, when I add a palloc statement in there it crashes:


PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
    int32        arg = PG_GETARG_INT32(0);
    palloc(sizeof(Point));
    PG_RETURN_INT32(arg + 1);
}

Running "SELECT add_one(1);" crashes the server. The logs show this:

2008-05-03 21:29:08 MDT LOG:  server process (PID 3008) was terminated
by exception 0xC0000005
2008-05-03 21:29:08 MDT HINT:  See C include file "ntstatus.h" for a
description of the hexadecimal value.
2008-05-03 21:29:08 MDT LOG:  terminating any other active server processes
2008-05-03 21:29:08 MDT LOG:  all server processes terminated; reinitializing
2008-05-03 21:29:09 MDT FATAL:  pre-existing shared memory block is still in use
2008-05-03 21:29:09 MDT HINT:  Check if there are any old server
processes still running, and terminate them.

I also get the exact same error when I try to run either the copytext
or concat_text functions from the same funcs_new.c file in the
tutorial directory. This essentially means that I cannot write any
UDFs that require memory allocation or text parameters. Heron seems to
be experiencing the same thing. Is this a bug in 8.3? Can anyone help?

pgsql-general by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Feature request
Next
From: ptjm@news-reader-radius.uniserve.com (Patrick TJ McPhee)
Date:
Subject: Re: Unloading a table consistently