postmaster core dumps with SPI_repalloc

From: "Andrey Y(dot) Mosienko" <feo(at)ttn(dot)ru>
To: Postgres <pgsql-general(at)postgresql(dot)org>
Subject: postmaster core dumps with SPI_repalloc
Date: 2002-05-14 10:19:10
Message-ID: 3CE0E49E.905EC7B9@ttn.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello All!

I noticed when I create memory pool with SPI_palloc(less than 100) and then
try to reallocate it with SPI_repalloc postmaster core dumps.

But when first SPI_palloc(100 or bigger) everything works fine!

What can be wrong?

Here is trigger example:

CREATE SEQUENCE base_id_seq;

CREATE TABLE "base" (
"id" int4 DEFAULT nextval('base_id_seq'::text) NOT NULL,
"field" text NOT NULL,
"field_m" text NOT NULL,
"field_n" text NOT NULL,
"changed" timestamp NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id"), UNIQUE ("id")
);

INSERT INTO "base" (field, field_m, field_n) VALUES ('test', 'test', 'test');

CREATE FUNCTION archive() RETURNS OPAQUE AS
'/home/feo/WORK/backup/archive.so' LANGUAGE 'C';

CREATE TRIGGER "archive" AFTER UPDATE
ON base FOR EACH ROW
EXECUTE PROCEDURE archive();

archive.c:

#include "executor/spi.h" /* this is what you need to work with SPI */
#include "commands/trigger.h" /* -"- and triggers */

extern Datum archive(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(archive);

Datum
archive(PG_FUNCTION_ARGS)
{
//TriggerData *trigdata = (TriggerData *) fcinfo->context;

int ret, i;
char* sql;
char* fields_names;
char* values;

// Ok ... this is a trigger function ...
// were we called from a trigger??
//
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "archive: not fired by trigger manager");

// Connect to the SPI manager
//
if( (ret = SPI_connect()) == SPI_OK_CONNECT ) {
fields_names = SPI_palloc(100);
values = SPI_palloc(100);
sql = SPI_palloc(40);

for (i = 0; i < 10; i++) {
SPI_repalloc(fields_names, sizeof(fields_names) + 100);
SPI_repalloc(values, sizeof(values) + 100);
};
SPI_pfree(fields_names);
SPI_pfree(values);
SPI_pfree(sql);

SPI_finish();
};
// Or if everything failes (no SPI connection)
// we'll just return ... nothing!
return PointerGetDatum(NULL);
}

PgSQL log:
DEBUG: query: update base set field_m = 'test4', changed = NOW() where id = '1';
DEBUG: server process (pid 5909) was terminated by signal 11

--
with respection Andrey Feofilactovich.
e-mail: feo(at)ttn(dot)ru, feo(at)feo(dot)org(dot)ru
ICQ: 28073807

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martín Marqués 2002-05-14 11:38:07 Re: restoreing dumps fail
Previous Message Thomas Beutin 2002-05-14 07:43:29 Re: Fast statement but slow function