8000 Back-patch fix and test case for bug #7516. · haying/postgres@1e23454 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e23454

Browse files
committed
Back-patch fix and test case for bug #7516.
Back-patch commits 9afc648 and b8fbbcf. The first of these is really a minor code cleanup to save a few cycles, but it turns out to provide a workaround for the misoptimization problem described in bug #7516. The second commit adds a regression test case. Back-patch the fix to all active branches. The test case only works as far back as 9.0, because it relies on plpgsql which isn't installed by default before that. (I didn't have success modifying it into an all-plperl form that still provoked a crash, though this may just reflect my lack of Perl-fu.)
1 parent dc447e1 commit 1e23454

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/pl/plperl/plperl.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,27 +1042,32 @@ plperl_call_handler(PG_FUNCTION_ARGS)
10421042
Datum retval;
10431043
plperl_call_data *save_call_data = current_call_data;
10441044
plperl_interp_desc *oldinterp = plperl_active_interp;
1045+
plperl_call_data this_call_data;
1046+
1047+
/* Initialize current-call status record */
1048+
MemSet(&this_call_data, 0, sizeof(this_call_data));
1049+
this_call_data.fcinfo = fcinfo;
10451050

10461051
PG_TRY();
10471052
{
1048-
current_call_data = NULL;
1053+
current_call_data = &this_call_data;
10491054
if (CALLED_AS_TRIGGER(fcinfo))
10501055
retval = PointerGetDatum(plperl_trigger_handler(fcinfo));
10511056
else
10521057
retval = plperl_func_handler(fcinfo);
10531058
}
10541059
PG_CATCH();
10551060
{
1056-
if (current_call_data && current_call_data->prodesc)
1057-
decrement_prodesc_refcount(current_call_data->prodesc);
1061+
if (this_call_data.prodesc)
1062+
decrement_prodesc_refcount(this_call_data.prodesc);
10581063
current_call_data = save_call_data;
10591064
activate_interpreter(oldinterp);
10601065
PG_RE_THROW();
10611066
}
10621067
PG_END_TRY();
10631068

1064-
if (current_call_data && current_call_data->prodesc)
1065-
decrement_prodesc_refcount(current_call_data->prodesc);
1069+
if (this_call_data.prodesc)
1070+
decrement_prodesc_refcount(this_call_data.prodesc);
10661071
current_call_data = save_call_data;
10671072
activate_interpreter(oldinterp);
10681073
return retval;
@@ -1399,13 +1404,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
13991404
ReturnSetInfo *rsi;
14001405
SV *array_ret = NULL;
14011406

1402-
/*
1403-
* Create the call_data beforing connecting to SPI, so that it is not
1404-
* allocated in the SPI memory context
1405-
*/
1406-
current_call_data = (plperl_call_data *) palloc0(sizeof(plperl_call_data));
1407-
current_call_data->fcinfo = fcinfo;
1408-
14091407
if (SPI_connect() != SPI_OK_CONNECT)
14101408
elog(ERROR, "could not connect to SPI manager");
14111409

@@ -1551,13 +1549,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
15511549
SV *svTD;
15521550
HV *hvTD;
15531551

1554-
/*
1555-
* Create the call_data beforing connecting to SPI, so that it is not
1556-
* allocated in the SPI memory context
1557-
*/
1558-
current_call_data = (plperl_call_data *) palloc0(sizeof(plperl_call_data));
1559-
current_call_data->fcinfo = fcinfo;
1560-
15611552
/* Connect to SPI manager */
15621553
if (SPI_connect() != SPI_OK_CONNECT)
15631554
elog(ERROR, "could not connect to SPI manager");

0 commit comments

Comments
 (0)
0