Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7aa066f

Browse files
committed
record_in and record_recv must be careful to return a separately
pfree'able result, since some callers expect to be able to pfreethe result of a pass-by-reference function. Per report from Chris Trawick.
1 parentd304067 commit7aa066f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

‎src/backend/utils/adt/rowtypes.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.8 2004/12/31 22:01:22 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.9 2005/04/18 17:11:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -54,6 +54,7 @@ record_in(PG_FUNCTION_ARGS)
5454
{
5555
char*string=PG_GETARG_CSTRING(0);
5656
OidtupType=PG_GETARG_OID(1);
57+
HeapTupleHeaderresult;
5758
int32tupTypmod;
5859
TupleDesctupdesc;
5960
HeapTupletuple;
@@ -244,11 +245,20 @@ record_in(PG_FUNCTION_ARGS)
244245

245246
tuple=heap_formtuple(tupdesc,values,nulls);
246247

248+
/*
249+
* We cannot return tuple->t_data because heap_formtuple allocates it
250+
* as part of a larger chunk, and our caller may expect to be able to
251+
* pfree our result. So must copy the info into a new palloc chunk.
252+
*/
253+
result= (HeapTupleHeader)palloc(tuple->t_len);
254+
memcpy(result,tuple->t_data,tuple->t_len);
255+
256+
heap_freetuple(tuple);
247257
pfree(buf.data);
248258
pfree(values);
249259
pfree(nulls);
250260

251-
PG_RETURN_HEAPTUPLEHEADER(tuple->t_data);
261+
PG_RETURN_HEAPTUPLEHEADER(result);
252262
}
253263

254264
/*
@@ -419,6 +429,7 @@ record_recv(PG_FUNCTION_ARGS)
419429
{
420430
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
421431
OidtupType=PG_GETARG_OID(1);
432+
HeapTupleHeaderresult;
422433
int32tupTypmod;
423434
TupleDesctupdesc;
424435
HeapTupletuple;
@@ -580,10 +591,19 @@ record_recv(PG_FUNCTION_ARGS)
580591

581592
tuple=heap_formtuple(tupdesc,values,nulls);
582593

594+
/*
595+
* We cannot return tuple->t_data because heap_formtuple allocates it
596+
* as part of a larger chunk, and our caller may expect to be able to
597+
* pfree our result. So must copy the info into a new palloc chunk.
598+
*/
599+
result= (HeapTupleHeader)palloc(tuple->t_len);
600+
memcpy(result,tuple->t_data,tuple->t_len);
601+
602+
heap_freetuple(tuple);
583603
pfree(values);
584604
pfree(nulls);
585605

586-
PG_RETURN_HEAPTUPLEHEADER(tuple->t_data);
606+
PG_RETURN_HEAPTUPLEHEADER(result);
587607
}
588608

589609
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp