mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Ensure the previous Perl interpreter selection is restored upon exit from
plperl_call_handler, in both the normal and error-exit paths. Per report from Alexey Klyukin.
This commit is contained in:
parent
818d2014c4
commit
3753017a20
@ -1,7 +1,7 @@
|
||||
/**********************************************************************
|
||||
* plperl.c - perl as a procedural language for PostgreSQL
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.123.2.7 2009/09/28 17:30:24 adunstan Exp $
|
||||
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.123.2.8 2009/10/31 18:12:20 tgl Exp $
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
@ -139,8 +139,8 @@ void _PG_init(void);
|
||||
static void plperl_init_interp(void);
|
||||
|
||||
static Datum plperl_func_handler(PG_FUNCTION_ARGS);
|
||||
|
||||
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS);
|
||||
|
||||
static plperl_proc_desc *compile_plperl_function(Oid fn_oid, bool is_trigger);
|
||||
|
||||
static SV *plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc);
|
||||
@ -359,11 +359,13 @@ check_interp(bool trusted)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Restore previous interpreter selection, if two are active
|
||||
*/
|
||||
static void
|
||||
restore_context(bool old_context)
|
||||
{
|
||||
if (trusted_context != old_context)
|
||||
if (interp_state == INTERP_BOTH && trusted_context != old_context)
|
||||
{
|
||||
if (old_context)
|
||||
PERL_SET_CONTEXT(plperl_trusted_interp);
|
||||
@ -847,9 +849,9 @@ Datum
|
||||
plperl_call_handler(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Datum retval;
|
||||
plperl_call_data *save_call_data;
|
||||
plperl_call_data *save_call_data = current_call_data;
|
||||
bool oldcontext = trusted_context;
|
||||
|
||||
save_call_data = current_call_data;
|
||||
PG_TRY();
|
||||
{
|
||||
if (CALLED_AS_TRIGGER(fcinfo))
|
||||
@ -860,11 +862,13 @@ plperl_call_handler(PG_FUNCTION_ARGS)
|
||||
PG_CATCH();
|
||||
{
|
||||
current_call_data = save_call_data;
|
||||
restore_context(oldcontext);
|
||||
PG_RE_THROW();
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
current_call_data = save_call_data;
|
||||
restore_context(oldcontext);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -1206,7 +1210,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
|
||||
Datum retval;
|
||||
ReturnSetInfo *rsi;
|
||||
SV *array_ret = NULL;
|
||||
bool oldcontext = trusted_context;
|
||||
|
||||
/*
|
||||
* Create the call_data beforing connecting to SPI, so that it is not
|
||||
@ -1346,9 +1349,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
|
||||
if (array_ret == NULL)
|
||||
SvREFCNT_dec(perlret);
|
||||
|
||||
current_call_data = NULL;
|
||||
restore_context(oldcontext);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -1361,7 +1361,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
|
||||
Datum retval;
|
||||
SV *svTD;
|
||||
HV *hvTD;
|
||||
bool oldcontext = trusted_context;
|
||||
|
||||
/*
|
||||
* Create the call_data beforing connecting to SPI, so that it is not
|
||||
@ -1449,8 +1448,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
|
||||
if (perlret)
|
||||
SvREFCNT_dec(perlret);
|
||||
|
||||
current_call_data = NULL;
|
||||
restore_context(oldcontext);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user