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

Commit38930e4

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 parentf16270a commit38930e4

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
@@ -1243,8 +1243,9 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
12431243
{
12441244
/*
12451245
* Initialize the magic SQLSTATE and SQLERRM variables for
1246-
* the exception block. We needn't do this until we have
1247-
* found a matching exception.
1246+
* the exception block; this also frees values from any
1247+
* prior use of the same exception. We needn't do this
1248+
* until we have found a matching exception.
12481249
*/
12491250
PLpgSQL_var*state_var;
12501251
PLpgSQL_var*errm_var;
@@ -1268,13 +1269,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
12681269

12691270
rc=exec_stmts(estate,exception->action);
12701271

1271-
free_var(state_var);
1272-
state_var->value= (Datum)0;
1273-
state_var->isnull= true;
1274-
free_var(errm_var);
1275-
errm_var->value= (Datum)0;
1276-
errm_var->isnull= true;
1277-
12781272
break;
12791273
}
12801274
}

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

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

26452645
(1 row)
26462646

2647+
create function excpt_test4() returns text as $$
2648+
begin
2649+
begin perform 1/0;
2650+
exception when others then return sqlerrm; end;
2651+
end; $$ language plpgsql;
2652+
select excpt_test4();
2653+
excpt_test4
2654+
------------------
2655+
division by zero
2656+
(1 row)
2657+
26472658
drop function excpt_test1();
26482659
drop function excpt_test2();
26492660
drop function excpt_test3();
2661+
drop function excpt_test4();
26502662
-- parameters of raise stmt can be expressions
26512663
create function raise_exprs() returns void as $$
26522664
declare

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,11 +2241,19 @@ begin
22412241
raise notice'% %', sqlstate, sqlerrm;
22422242
end;
22432243
end; $$ language plpgsql;
2244-
22452244
select excpt_test3();
2245+
2246+
createfunctionexcpt_test4() returnstextas $$
2247+
begin
2248+
begin perform1/0;
2249+
exception when others then return sqlerrm; end;
2250+
end; $$ language plpgsql;
2251+
select excpt_test4();
2252+
22462253
dropfunction excpt_test1();
22472254
dropfunction excpt_test2();
22482255
dropfunction excpt_test3();
2256+
dropfunction excpt_test4();
22492257

22502258
-- parameters of raise stmt can be expressions
22512259
createfunctionraise_exprs() returns voidas $$

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp