summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNoah Misch2015-02-26 04:48:28 +0000
committerNoah Misch2015-02-26 04:49:02 +0000
commit034d05dbdf6340247b58c80640b2cdfc772f4ee1 (patch)
tree5889b30ce901c886d7679afdb535e5a616dfbde0 /src/test
parentf7b41902a6737c682e6311455976f1205014cb8b (diff)
Free SQLSTATE and SQLERRM no earlier than other PL/pgSQL variables.
"RETURN SQLERRM" prompted plpgsql_exec_function() to read from freed memory. Back-patch to 9.0 (all supported versions). Little code ran between the premature free and the read, so non-assert builds are unlikely to witness user-visible consequences.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/plpgsql.out12
-rw-r--r--src/test/regress/sql/plpgsql.sql10
2 files changed, 21 insertions, 1 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index bfabcbc8b44..09df3901620 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -2498,9 +2498,21 @@ NOTICE: P0001 user exception
(1 row)
+create function excpt_test4() returns text as $$
+begin
+ begin perform 1/0;
+ exception when others then return sqlerrm; end;
+end; $$ language plpgsql;
+select excpt_test4();
+ excpt_test4
+------------------
+ division by zero
+(1 row)
+
drop function excpt_test1();
drop function excpt_test2();
drop function excpt_test3();
+drop function excpt_test4();
-- parameters of raise stmt can be expressions
create function raise_exprs() returns void as $$
declare
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index 14fb4578c60..78e1aa8a58c 100644
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -2118,11 +2118,19 @@ begin
raise notice '% %', sqlstate, sqlerrm;
end;
end; $$ language plpgsql;
-
select excpt_test3();
+
+create function excpt_test4() returns text as $$
+begin
+ begin perform 1/0;
+ exception when others then return sqlerrm; end;
+end; $$ language plpgsql;
+select excpt_test4();
+
drop function excpt_test1();
drop function excpt_test2();
drop function excpt_test3();
+drop function excpt_test4();
-- parameters of raise stmt can be expressions
create function raise_exprs() returns void as $$