Re: BUG #1604: Composite types, triggers, and INET_CLIENT_ADDR() function
От | Tom Lane |
---|---|
Тема | Re: BUG #1604: Composite types, triggers, and INET_CLIENT_ADDR() function |
Дата | |
Msg-id | 23671.1113844377@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | BUG #1604: Composite types, triggers, and INET_CLIENT_ADDR() function ("Chris Trawick" <ctrawick@cultured.net>) |
Список | pgsql-bugs |
"Chris Trawick" <ctrawick@cultured.net> writes: > I'm encountering an error when using a plpgsql insert trigger to > automatically log the client connection information using > INET_CLIENT_ADDR(). Thanks for the clear bug report. The error is actually generic to any composite-type operation. Here's the patch. regards, tom lane Index: rowtypes.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/rowtypes.c,v retrieving revision 1.8 diff -c -r1.8 rowtypes.c *** rowtypes.c 31 Dec 2004 22:01:22 -0000 1.8 --- rowtypes.c 18 Apr 2005 17:02:43 -0000 *************** *** 54,59 **** --- 54,60 ---- { char *string = PG_GETARG_CSTRING(0); Oid tupType = PG_GETARG_OID(1); + HeapTupleHeader result; int32 tupTypmod; TupleDesc tupdesc; HeapTuple tuple; *************** *** 244,254 **** tuple = heap_formtuple(tupdesc, values, nulls); pfree(buf.data); pfree(values); pfree(nulls); ! PG_RETURN_HEAPTUPLEHEADER(tuple->t_data); } /* --- 245,264 ---- tuple = heap_formtuple(tupdesc, values, nulls); + /* + * We cannot return tuple->t_data because heap_formtuple allocates it + * as part of a larger chunk, and our caller may expect to be able to + * pfree our result. So must copy the info into a new palloc chunk. + */ + result = (HeapTupleHeader) palloc(tuple->t_len); + memcpy(result, tuple->t_data, tuple->t_len); + + heap_freetuple(tuple); pfree(buf.data); pfree(values); pfree(nulls); ! PG_RETURN_HEAPTUPLEHEADER(result); } /* *************** *** 419,424 **** --- 429,435 ---- { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); Oid tupType = PG_GETARG_OID(1); + HeapTupleHeader result; int32 tupTypmod; TupleDesc tupdesc; HeapTuple tuple; *************** *** 580,589 **** tuple = heap_formtuple(tupdesc, values, nulls); pfree(values); pfree(nulls); ! PG_RETURN_HEAPTUPLEHEADER(tuple->t_data); } /* --- 591,609 ---- tuple = heap_formtuple(tupdesc, values, nulls); + /* + * We cannot return tuple->t_data because heap_formtuple allocates it + * as part of a larger chunk, and our caller may expect to be able to + * pfree our result. So must copy the info into a new palloc chunk. + */ + result = (HeapTupleHeader) palloc(tuple->t_len); + memcpy(result, tuple->t_data, tuple->t_len); + + heap_freetuple(tuple); pfree(values); pfree(nulls); ! PG_RETURN_HEAPTUPLEHEADER(result); } /*
В списке pgsql-bugs по дате отправления: