diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 0fe8df2734..eb76202ec7 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1042,10 +1042,15 @@ plperl_call_handler(PG_FUNCTION_ARGS) Datum retval; plperl_call_data *save_call_data = current_call_data; plperl_interp_desc *oldinterp = plperl_active_interp; + plperl_call_data this_call_data; + + /* Initialize current-call status record */ + MemSet(&this_call_data, 0, sizeof(this_call_data)); + this_call_data.fcinfo = fcinfo; PG_TRY(); { - current_call_data = NULL; + current_call_data = &this_call_data; if (CALLED_AS_TRIGGER(fcinfo)) retval = PointerGetDatum(plperl_trigger_handler(fcinfo)); else @@ -1053,16 +1058,16 @@ plperl_call_handler(PG_FUNCTION_ARGS) } PG_CATCH(); { - if (current_call_data && current_call_data->prodesc) - decrement_prodesc_refcount(current_call_data->prodesc); + if (this_call_data.prodesc) + decrement_prodesc_refcount(this_call_data.prodesc); current_call_data = save_call_data; activate_interpreter(oldinterp); PG_RE_THROW(); } PG_END_TRY(); - if (current_call_data && current_call_data->prodesc) - decrement_prodesc_refcount(current_call_data->prodesc); + if (this_call_data.prodesc) + decrement_prodesc_refcount(this_call_data.prodesc); current_call_data = save_call_data; activate_interpreter(oldinterp); return retval; @@ -1399,13 +1404,6 @@ plperl_func_handler(PG_FUNCTION_ARGS) ReturnSetInfo *rsi; SV *array_ret = NULL; - /* - * Create the call_data beforing connecting to SPI, so that it is not - * allocated in the SPI memory context - */ - current_call_data = (plperl_call_data *) palloc0(sizeof(plperl_call_data)); - current_call_data->fcinfo = fcinfo; - if (SPI_connect() != SPI_OK_CONNECT) elog(ERROR, "could not connect to SPI manager"); @@ -1551,13 +1549,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS) SV *svTD; HV *hvTD; - /* - * Create the call_data beforing connecting to SPI, so that it is not - * allocated in the SPI memory context - */ - current_call_data = (plperl_call_data *) palloc0(sizeof(plperl_call_data)); - current_call_data->fcinfo = fcinfo; - /* Connect to SPI manager */ if (SPI_connect() != SPI_OK_CONNECT) elog(ERROR, "could not connect to SPI manager");