mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-01 19:45:33 +08:00
record_in and record_recv must be careful to return a separately
pfree'able result, since some callers expect to be able to pfree the result of a pass-by-reference function. Per report from Chris Trawick.
This commit is contained in:
parent
d304067695
commit
7aa066f11d
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.8 2004/12/31 22:01:22 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.9 2005/04/18 17:11:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -54,6 +54,7 @@ record_in(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *string = PG_GETARG_CSTRING(0);
|
||||
Oid tupType = PG_GETARG_OID(1);
|
||||
HeapTupleHeader result;
|
||||
int32 tupTypmod;
|
||||
TupleDesc tupdesc;
|
||||
HeapTuple tuple;
|
||||
@ -244,11 +245,20 @@ record_in(PG_FUNCTION_ARGS)
|
||||
|
||||
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(tuple->t_data);
|
||||
PG_RETURN_HEAPTUPLEHEADER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -419,6 +429,7 @@ record_recv(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
Oid tupType = PG_GETARG_OID(1);
|
||||
HeapTupleHeader result;
|
||||
int32 tupTypmod;
|
||||
TupleDesc tupdesc;
|
||||
HeapTuple tuple;
|
||||
@ -580,10 +591,19 @@ record_recv(PG_FUNCTION_ARGS)
|
||||
|
||||
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(tuple->t_data);
|
||||
PG_RETURN_HEAPTUPLEHEADER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user