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