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

Commit034d05d

Browse files
committed
Free SQLSTATE and SQLERRM no earlier than other PL/pgSQL variables.
"RETURN SQLERRM" prompted plpgsql_exec_function() to read from freedmemory. Back-patch to 9.0 (all supported versions). Little code ranbetween the premature free and the read, so non-assert builds areunlikely to witness user-visible consequences.
1 parentf7b4190 commit034d05d

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,9 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
11231123
{
11241124
/*
11251125
* Initialize the magic SQLSTATE and SQLERRM variables for
1126-
* the exception block. We needn't do this until we have
1127-
* found a matching exception.
1126+
* the exception block; this also frees values from any
1127+
* prior use of the same exception. We needn't do this
1128+
* until we have found a matching exception.
11281129
*/
11291130
PLpgSQL_var*state_var;
11301131
PLpgSQL_var*errm_var;
@@ -1148,13 +1149,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
11481149

11491150
rc=exec_stmts(estate,exception->action);
11501151

1151-
free_var(state_var);
1152-
state_var->value= (Datum)0;
1153-
state_var->isnull= true;
1154-
free_var(errm_var);
1155-
errm_var->value= (Datum)0;
1156-
errm_var->isnull= true;
1157-
11581152
break;
11591153
}
11601154
}

‎src/test/regress/expected/plpgsql.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,9 +2498,21 @@ NOTICE: P0001 user exception
24982498

24992499
(1 row)
25002500

2501+
create function excpt_test4() returns text as $$
2502+
begin
2503+
begin perform 1/0;
2504+
exception when others then return sqlerrm; end;
2505+
end; $$ language plpgsql;
2506+
select excpt_test4();
2507+
excpt_test4
2508+
------------------
2509+
division by zero
2510+
(1 row)
2511+
25012512
drop function excpt_test1();
25022513
drop function excpt_test2();
25032514
drop function excpt_test3();
2515+
drop function excpt_test4();
25042516
-- parameters of raise stmt can be expressions
25052517
create function raise_exprs() returns void as $$
25062518
declare

‎src/test/regress/sql/plpgsql.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,19 @@ begin
21182118
raise notice'% %', sqlstate, sqlerrm;
21192119
end;
21202120
end; $$ language plpgsql;
2121-
21222121
select excpt_test3();
2122+
2123+
createfunctionexcpt_test4() returnstextas $$
2124+
begin
2125+
begin perform1/0;
2126+
exception when others then return sqlerrm; end;
2127+
end; $$ language plpgsql;
2128+
select excpt_test4();
2129+
21232130
dropfunction excpt_test1();
21242131
dropfunction excpt_test2();
21252132
dropfunction excpt_test3();
2133+
dropfunction excpt_test4();
21262134

21272135
-- parameters of raise stmt can be expressions
21282136
createfunctionraise_exprs() returns voidas $$

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp