@@ -1695,27 +1695,32 @@ plperl_call_handler(PG_FUNCTION_ARGS)
1695
1695
Datum retval ;
1696
1696
plperl_call_data * save_call_data = current_call_data ;
1697
1697
plperl_interp_desc * oldinterp = plperl_active_interp ;
1698
+ plperl_call_data this_call_data ;
1699
+
1700
+ /* Initialize current-call status record */
1701
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1702
+ this_call_data .fcinfo = fcinfo ;
1698
1703
1699
1704
PG_TRY ();
1700
1705
{
1701
- current_call_data = NULL ;
1706
+ current_call_data = & this_call_data ;
1702
1707
if (CALLED_AS_TRIGGER (fcinfo ))
1703
1708
retval = PointerGetDatum (plperl_trigger_handler (fcinfo ));
1704
1709
else
1705
1710
retval = plperl_func_handler (fcinfo );
1706
1711
}
1707
1712
PG_CATCH ();
1708
1713
{
1709
- if (current_call_data && current_call_data -> prodesc )
1710
- decrement_prodesc_refcount (current_call_data -> prodesc );
1714
+ if (this_call_data . prodesc )
1715
+ decrement_prodesc_refcount (this_call_data . prodesc );
1711
1716
current_call_data = save_call_data ;
1712
1717
activate_interpreter (oldinterp );
1713
1718
PG_RE_THROW ();
1714
1719
}
1715
1720
PG_END_TRY ();
1716
1721
1717
- if (current_call_data && current_call_data -> prodesc )
1718
- decrement_prodesc_refcount (current_call_data -> prodesc );
1722
+ if (this_call_data . prodesc )
1723
+ decrement_prodesc_refcount (this_call_data . prodesc );
1719
1724
current_call_data = save_call_data ;
1720
1725
activate_interpreter (oldinterp );
1721
1726
return retval ;
@@ -1735,8 +1740,12 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1735
1740
plperl_proc_desc desc ;
1736
1741
plperl_call_data * save_call_data = current_call_data ;
1737
1742
plperl_interp_desc * oldinterp = plperl_active_interp ;
1743
+ plperl_call_data this_call_data ;
1738
1744
ErrorContextCallback pl_error_context ;
1739
1745
1746
+ /* Initialize current-call status record */
1747
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1748
+
1740
1749
/* Set up a callback for error reporting */
1741
1750
pl_error_context .callback = plperl_inline_callback ;
1742
1751
pl_error_context .previous = error_context_stack ;
@@ -1767,14 +1776,15 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1767
1776
desc .nargs = 0 ;
1768
1777
desc .reference = NULL ;
1769
1778
1779
+ this_call_data .fcinfo = & fake_fcinfo ;
1780
+ this_call_data .prodesc = & desc ;
1781
+ /* we do not bother with refcounting the fake prodesc */
1782
+
1770
1783
PG_TRY ();
1771
1784
{
1772
1785
SV * perlret ;
1773
1786
1774
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
1775
- current_call_data -> fcinfo = & fake_fcinfo ;
1776
- current_call_data -> prodesc = & desc ;
1777
- /* we do not bother with refcounting the fake prodesc */
1787
+ current_call_data = & this_call_data ;
1778
1788
1779
1789
if (SPI_connect () != SPI_OK_CONNECT )
1780
1790
elog (ERROR , "could not connect to SPI manager" );
@@ -2157,13 +2167,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
2157
2167
ReturnSetInfo * rsi ;
2158
2168
ErrorContextCallback pl_error_context ;
2159
2169
2160
- /*
2161
- * Create the call_data before connecting to SPI, so that it is not
2162
- * allocated in the SPI memory context
2163
- */
2164
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
2165
- current_call_data -> fcinfo = fcinfo ;
2166
-
2167
2170
if (SPI_connect () != SPI_OK_CONNECT )
2168
2171
elog (ERROR , "could not connect to SPI manager" );
2169
2172
@@ -2276,13 +2279,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
2276
2279
HV * hvTD ;
2277
2280
ErrorContextCallback pl_error_context ;
2278
2281
2279
- /*
2280
- * Create the call_data before connecting to SPI, so that it is not
2281
- * allocated in the SPI memory context
2282
- */
2283
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
2284
- current_call_data -> fcinfo = fcinfo ;
2285
-
2286
2282
/* Connect to SPI manager */
2287
2283
if (SPI_connect () != SPI_OK_CONNECT )
2288
2284
elog (ERROR , "could not connect to SPI manager" );
0 commit comments