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

Commit77a41e7

Browse files
committed
Fix plpgsql to avoid reference to already-freed memory when returning a
pass-by-reference data type and the RETURN statement is within an EXCEPTIONblock. Bug introduced by my fix of 2007-01-28 to use per-subtransactionExprContexts/EStates; since that wasn't back-patched into older branches,only 8.2 and HEAD are affected. Per report from Gary Winslow.
1 parentdfa5887 commit77a41e7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.194 2007/04/16 17:21:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.195 2007/04/19 16:33:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -987,6 +987,25 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
987987

988988
estate->err_text=gettext_noop("during statement block exit");
989989

990+
/*
991+
* If the block ended with RETURN, we may need to copy the return
992+
* value out of the subtransaction eval_context. This is currently
993+
* only needed for scalar result types --- rowtype values will
994+
* always exist in the function's own memory context.
995+
*/
996+
if (rc==PLPGSQL_RC_RETURN&&
997+
!estate->retisset&&
998+
!estate->retisnull&&
999+
estate->rettupdesc==NULL)
1000+
{
1001+
int16resTypLen;
1002+
boolresTypByVal;
1003+
1004+
get_typlenbyval(estate->rettype,&resTypLen,&resTypByVal);
1005+
estate->retval=datumCopy(estate->retval,
1006+
resTypByVal,resTypLen);
1007+
}
1008+
9901009
/* Commit the inner transaction, return to outer xact context */
9911010
ReleaseCurrentSubTransaction();
9921011
MemoryContextSwitchTo(oldcontext);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp