@@ -1244,27 +1244,32 @@ plperl_call_handler(PG_FUNCTION_ARGS)
1244
1244
Datum retval ;
1245
1245
plperl_call_data * save_call_data = current_call_data ;
1246
1246
plperl_interp_desc * oldinterp = plperl_active_interp ;
1247
+ plperl_call_data this_call_data ;
1248
+
1249
+ /* Initialize current-call status record */
1250
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1251
+ this_call_data .fcinfo = fcinfo ;
1247
1252
1248
1253
PG_TRY ();
1249
1254
{
1250
- current_call_data = NULL ;
1255
+ current_call_data = & this_call_data ;
1251
1256
if (CALLED_AS_TRIGGER (fcinfo ))
1252
1257
retval = PointerGetDatum (plperl_trigger_handler (fcinfo ));
1253
1258
else
1254
1259
retval = plperl_func_handler (fcinfo );
1255
1260
}
1256
1261
PG_CATCH ();
1257
1262
{
1258
- if (current_call_data && current_call_data -> prodesc )
1259
- decrement_prodesc_refcount (current_call_data -> prodesc );
1263
+ if (this_call_data . prodesc )
1264
+ decrement_prodesc_refcount (this_call_data . prodesc );
1260
1265
current_call_data = save_call_data ;
1261
1266
activate_interpreter (oldinterp );
1262
1267
PG_RE_THROW ();
1263
1268
}
1264
1269
PG_END_TRY ();
1265
1270
1266
- if (current_call_data && current_call_data -> prodesc )
1267
- decrement_prodesc_refcount (current_call_data -> prodesc );
1271
+ if (this_call_data . prodesc )
1272
+ decrement_prodesc_refcount (this_call_data . prodesc );
1268
1273
current_call_data = save_call_data ;
1269
1274
activate_interpreter (oldinterp );
1270
1275
return retval ;
@@ -1284,8 +1289,12 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1284
1289
plperl_proc_desc desc ;
1285
1290
plperl_call_data * save_call_data = current_call_data ;
1286
1291
plperl_interp_desc * oldinterp = plperl_active_interp ;
1292
+ plperl_call_data this_call_data ;
1287
1293
ErrorContextCallback pl_error_context ;
1288
1294
1295
+ /* Initialize current-call status record */
1296
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1297
+
1289
1298
/* Set up a callback for error reporting */
1290
1299
pl_error_context .callback = plperl_inline_callback ;
1291
1300
pl_error_context .previous = error_context_stack ;
@@ -1316,14 +1325,15 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1316
1325
desc .nargs = 0 ;
1317
1326
desc .reference = NULL ;
1318
1327
1328
+ this_call_data .fcinfo = & fake_fcinfo ;
1329
+ this_call_data .prodesc = & desc ;
1330
+ /* we do not bother with refcounting the fake prodesc */
1331
+
1319
1332
PG_TRY ();
1320
1333
{
1321
1334
SV * perlret ;
1322
1335
1323
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
1324
- current_call_data -> fcinfo = & fake_fcinfo ;
1325
- current_call_data -> prodesc = & desc ;
1326
- /* we do not bother with refcounting the fake prodesc */
1336
+ current_call_data = & this_call_data ;
1327
1337
1328
1338
if (SPI_connect () != SPI_OK_CONNECT )
1329
1339
elog (ERROR , "could not connect to SPI manager" );
@@ -1672,13 +1682,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
1672
1682
SV * array_ret = NULL ;
1673
1683
ErrorContextCallback pl_error_context ;
1674
1684
1675
- /*
1676
- * Create the call_data beforing connecting to SPI, so that it is not
1677
- * allocated in the SPI memory context
1678
- */
1679
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
1680
- current_call_data -> fcinfo = fcinfo ;
1681
-
1682
1685
if (SPI_connect () != SPI_OK_CONNECT )
1683
1686
elog (ERROR , "could not connect to SPI manager" );
1684
1687
@@ -1832,13 +1835,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
1832
1835
HV * hvTD ;
1833
1836
ErrorContextCallback pl_error_context ;
1834
1837
1835
- /*
1836
- * Create the call_data beforing connecting to SPI, so that it is not
1837
- * allocated in the SPI memory context
1838
- */
1839
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
1840
- current_call_data -> fcinfo = fcinfo ;
1841
-
1842
1838
/* Connect to SPI manager */
1843
1839
if (SPI_connect () != SPI_OK_CONNECT )
1844
1840
elog (ERROR , "could not connect to SPI manager" );
0 commit comments