On Thu, Jan 14, 2010 at 08:45:06PM +0000, Tim Bunce wrote:
> On Thu, Jan 14, 2010 at 06:41:52PM +0000, Tim Bunce wrote:
> > > > David E. Wheeler wrote:
> > > >> Found in 8.4.2, replicated in HEAD. Steps:
> > > >> 
> > > >> 1. Create PL/Perl function.
> > > >> 2. Run it.
> > > >> 3. Create same function with PL/PerlU
> > > >> 4. Run it.
> > > >> 5. Create same function again with PL/Perl
> > > >> 6. Boom.
> > > 
> > > panic: free from wrong pool.
> > > LOG:  server process (PID 15697) exited with exit code 255
> > > 
> > > There's no core dump (thank you, perl). The lower-case panic message
> > > must be from libperl because PG has no such message.  I guess that we
> > > probably need to fix this by changing the timing of interpreter
> > > switching relative to throwing away the old compiled function ...
> > 
> > [...]
> 
> > That was using a cvs head (via git) from ~ the 9th of Jan.
> > I got the same failure after applying my feature1a-utils patch,
> > but then applying my feature1b-misc patch fixed it.
> 
> Not quite out of the woods. My next patch adds in destruction of the
> perl interpreters. That's showing the 'wrong pool' in a different way:
> 
>     Scalars leaked: -1
>     Scalars leaked: 1
> 
> I want to get some more patches into the commitfest before it closes.
> After that I'll look into this some more, if someone else hasn't got to
> it first.

The attached patch fixes the (longstanding) problem.

It should apply cleanly over the "Miscellaneous changes to plperl"
patch (which I believe Andrew Dunstan intends to commit shortly).

A backport of the core fix in plperl.c should be simple.

Tim.

diff --git a/src/pl/plperl/expected/plperl_plperlu.out b/src/pl/plperl/expected/plperl_plperlu.out
index e940f71..acc9dd4 100644
*** a/src/pl/plperl/expected/plperl_plperlu.out
--- b/src/pl/plperl/expected/plperl_plperlu.out
*************** CONTEXT:  PL/Perl function "bar"
*** 17,19 ****
--- 17,65 ----
  SELECT * FROM foo(); -- used to cause backend crash (after switching to plperlu)
  ERROR:  syntax error at or near "invalid" at line 4. at line 2.
  CONTEXT:  PL/Perl function "foo"
+ -- test redefinition of specific SP switching languages
+ -- http://archives.postgresql.org/pgsql-bugs/2010-01/msg00116.php
+ -- plperl first
+ create or replace function foo(text) returns text language plperl  as 'shift';
+ select foo('hey');
+  foo 
+ -----
+  hey
+ (1 row)
+ 
+ create or replace function foo(text) returns text language plperlu as 'shift';
+ select foo('hey');
+  foo 
+ -----
+  hey
+ (1 row)
+ 
+ create or replace function foo(text) returns text language plperl  as 'shift';
+ select foo('hey');
+  foo 
+ -----
+  hey
+ (1 row)
+ 
+ -- plperlu first
+ create or replace function bar(text) returns text language plperlu as 'shift';
+ select bar('hey');
+  bar 
+ -----
+  hey
+ (1 row)
+ 
+ create or replace function bar(text) returns text language plperl  as 'shift';
+ select bar('hey');
+  bar 
+ -----
+  hey
+ (1 row)
+ 
+ create or replace function bar(text) returns text language plperlu as 'shift';
+ select bar('hey');
+  bar 
+ -----
+  hey
+ (1 row)
+ 
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 2111936..75cf543 100644
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
*************** compile_plperl_function(Oid fn_oid, bool
*** 1760,1767 ****
  		{
  			hash_search(plperl_proc_hash, internal_proname,
  						HASH_REMOVE, NULL);
! 			if (prodesc->reference)
  				SvREFCNT_dec(prodesc->reference);
  			free(prodesc->proname);
  			free(prodesc);
  			prodesc = NULL;
--- 1760,1770 ----
  		{
  			hash_search(plperl_proc_hash, internal_proname,
  						HASH_REMOVE, NULL);
! 			if (prodesc->reference) {
! 				select_perl_context(prodesc->lanpltrusted);
  				SvREFCNT_dec(prodesc->reference);
+ 				restore_context(oldcontext);
+ 			}
  			free(prodesc->proname);
  			free(prodesc);
  			prodesc = NULL;
diff --git a/src/pl/plperl/sql/plperl_plperlu.sql b/src/pl/plperl/sql/plperl_plperlu.sql
index 15b5aa2..cbc5080 100644
*** a/src/pl/plperl/sql/plperl_plperlu.sql
--- b/src/pl/plperl/sql/plperl_plperlu.sql
*************** $$ LANGUAGE plperlu; -- compile plperlu 
*** 16,18 ****
--- 16,37 ----
  SELECT * FROM bar(); -- throws exception normally (running plperl)
  SELECT * FROM foo(); -- used to cause backend crash (after switching to plperlu)
  
+ -- test redefinition of specific SP switching languages
+ -- http://archives.postgresql.org/pgsql-bugs/2010-01/msg00116.php
+ 
+ -- plperl first
+ create or replace function foo(text) returns text language plperl  as 'shift';
+ select foo('hey');
+ create or replace function foo(text) returns text language plperlu as 'shift';
+ select foo('hey');
+ create or replace function foo(text) returns text language plperl  as 'shift';
+ select foo('hey');
+ 
+ -- plperlu first
+ create or replace function bar(text) returns text language plperlu as 'shift';
+ select bar('hey');
+ create or replace function bar(text) returns text language plperl  as 'shift';
+ select bar('hey');
+ create or replace function bar(text) returns text language plperlu as 'shift';
+ select bar('hey');
+ 
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to