"Chris Trawick" <[EMAIL PROTECTED]> 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); } /* ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq