Re: invalid memory alloc after insert with c trigger function - Mailing list pgsql-general

From Gregory Stark
Subject Re: invalid memory alloc after insert with c trigger function
Date
Msg-id 87ejkvyhso.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: invalid memory alloc after insert with c trigger function  (Dudás József <dj1999@freemail.hu>)
List pgsql-general
Dudás József <dj1999@freemail.hu> writes:

> Sorry I do not understand. I did not convert float to varchar.

Well then there's some kind of miscommunication here. Your crash is happening
trying to read a varchar column later. Someone sometime is putting data into
that varchar column. I don't understand how the snippets of code handling
floats and numerics relate to the varchar that's causing your crash.


I still don't understand what you're doing and what's going on but there are a
few strange things in this code snippet:

> attnum[0] = SPI_fnumber( tupdesc, "deviza_kod" );
> datums[0] = DirectFunctionCall1(textin, CStringGetDatum( _selectFunction(
> "SELECT ertek FROM foo WHERE parameter='currency'" ) ) );
> if ( attnum[0] == PointerGetDatum( NULL ) ) {
>      elog( ERROR, "Hianyzo deviza" );
>      SPI_finish(); // zárunk
>      return PointerGetDatum(NULL); // vissza
> }

You test attnum[0] == PointerGetDatum(NULL) but attnum contains the result of
SPI_fnumber which isn't a datum at all, it's an attribute number which is an
integer. In case of error it returns SPI_ERROR_NOATTRIBUTE which is -9.

That said if your function is a function which takes PG_FUNCTION_ARGS then the
right way to return NULL is with PG_RETURN_NULL(). Merely returning a
PointerGetDatum(NULL) isn't good enough.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com


pgsql-general by date:

Previous
From: Dudás József
Date:
Subject: Re: invalid memory alloc after insert with c trigger function
Next
From: Richard Huxton
Date:
Subject: Re: ERROR: domain domain1 does not allow null values