summaryrefslogtreecommitdiff
path: root/src/pl/plperl/expected/plperl.out
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-09-09 20:32:54 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-09-09 20:32:54 -0400
commit59f23fe8d4eb0b95f029eaffdbcadc59d51f45cc (patch)
treec2a968d2bb9ff4da51ee181b60401af4a8b021de /src/pl/plperl/expected/plperl.out
parent843363b8d59e685b57a2f88c864a7041d44ffc06 (diff)
Make plperl safe against functions that are redefined while running.
validate_plperl_function() supposed that it could free an old plperl_proc_desc struct immediately upon detecting that it was stale. However, if a plperl function is called recursively, this could result in deleting the struct out from under an outer invocation, leading to misbehavior or crashes. Add a simple reference-count mechanism to ensure that such structs are freed only when the last reference goes away. Per investigation of bug #7516 from Marko Tiikkaja. I am not certain that this error explains his report, because he says he didn't have any recursive calls --- but it's hard to see how else it could have crashed right there. In any case, this definitely fixes some problems in the area. Back-patch to all active branches.
Diffstat (limited to 'src/pl/plperl/expected/plperl.out')
-rw-r--r--src/pl/plperl/expected/plperl.out18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/pl/plperl/expected/plperl.out b/src/pl/plperl/expected/plperl.out
index 906dc15e0ca..29c1d11c447 100644
--- a/src/pl/plperl/expected/plperl.out
+++ b/src/pl/plperl/expected/plperl.out
@@ -693,3 +693,21 @@ $$ LANGUAGE plperl;
SELECT text_scalarref();
ERROR: PL/Perl function must return reference to hash or array
CONTEXT: PL/Perl function "text_scalarref"
+-- check safe behavior when a function body is replaced during execution
+CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS $$
+ spi_exec_query('CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS \'return $_[0] * 3;\' LANGUAGE plperl;');
+ spi_exec_query('select self_modify(42) AS a');
+ return $_[0] * 2;
+$$ LANGUAGE plperl;
+SELECT self_modify(42);
+ self_modify
+-------------
+ 84
+(1 row)
+
+SELECT self_modify(42);
+ self_modify
+-------------
+ 126
+(1 row)
+