From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Chris Trawick" <ctrawick(at)cultured(dot)net> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #1604: Composite types, triggers, and INET_CLIENT_ADDR() function |
Date: | 2005-04-18 17:12:57 |
Message-ID: | 23671.1113844377@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
"Chris Trawick" <ctrawick(at)cultured(dot)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);
}
/*
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-04-18 21:05:58 | Re: Problem with pgdump_all |
Previous Message | Márcio A. Sepp | 2005-04-18 16:12:37 | Problem with pgdump_all |