@@ -1705,27 +1705,32 @@ plperl_call_handler(PG_FUNCTION_ARGS)
1705
1705
Datum retval ;
1706
1706
plperl_call_data * save_call_data = current_call_data ;
1707
1707
plperl_interp_desc * oldinterp = plperl_active_interp ;
1708
+ plperl_call_data this_call_data ;
1709
+
1710
+ /* Initialize current-call status record */
1711
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1712
+ this_call_data .fcinfo = fcinfo ;
1708
1713
1709
1714
PG_TRY ();
1710
1715
{
1711
- current_call_data = NULL ;
1716
+ current_call_data = & this_call_data ;
1712
1717
if (CALLED_AS_TRIGGER (fcinfo ))
1713
1718
retval = PointerGetDatum (plperl_trigger_handler (fcinfo ));
1714
1719
else
1715
1720
retval = plperl_func_handler (fcinfo );
1716
1721
}
1717
1722
PG_CATCH ();
1718
1723
{
1719
- if (current_call_data && current_call_data -> prodesc )
1720
- decrement_prodesc_refcount (current_call_data -> prodesc );
1724
+ if (this_call_data . prodesc )
1725
+ decrement_prodesc_refcount (this_call_data . prodesc );
1721
1726
current_call_data = save_call_data ;
1722
1727
activate_interpreter (oldinterp );
1723
1728
PG_RE_THROW ();
1724
1729
}
1725
1730
PG_END_TRY ();
1726
1731
1727
- if (current_call_data && current_call_data -> prodesc )
1728
- decrement_prodesc_refcount (current_call_data -> prodesc );
1732
+ if (this_call_data . prodesc )
1733
+ decrement_prodesc_refcount (this_call_data . prodesc );
1729
1734
current_call_data = save_call_data ;
1730
1735
activate_interpreter (oldinterp );
1731
1736
return retval ;
@@ -1745,8 +1750,12 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1745
1750
plperl_proc_desc desc ;
1746
1751
plperl_call_data * save_call_data = current_call_data ;
1747
1752
plperl_interp_desc * oldinterp = plperl_active_interp ;
1753
+ plperl_call_data this_call_data ;
1748
1754
ErrorContextCallback pl_error_context ;
1749
1755
1756
+ /* Initialize current-call status record */
1757
+ MemSet (& this_call_data , 0 , sizeof (this_call_data ));
1758
+
1750
1759
/* Set up a callback for error reporting */
1751
1760
pl_error_context .callback = plperl_inline_callback ;
1752
1761
pl_error_context .previous = error_context_stack ;
@@ -1777,14 +1786,15 @@ plperl_inline_handler(PG_FUNCTION_ARGS)
1777
1786
desc .nargs = 0 ;
1778
1787
desc .reference = NULL ;
1779
1788
1789
+ this_call_data .fcinfo = & fake_fcinfo ;
1790
+ this_call_data .prodesc = & desc ;
1791
+ /* we do not bother with refcounting the fake prodesc */
1792
+
1780
1793
PG_TRY ();
1781
1794
{
1782
1795
SV * perlret ;
1783
1796
1784
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
1785
- current_call_data -> fcinfo = & fake_fcinfo ;
1786
- current_call_data -> prodesc = & desc ;
1787
- /* we do not bother with refcounting the fake prodesc */
1797
+ current_call_data = & this_call_data ;
1788
1798
1789
1799
if (SPI_connect () != SPI_OK_CONNECT )
1790
1800
elog (ERROR , "could not connect to SPI manager" );
@@ -2167,13 +2177,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
2167
2177
ReturnSetInfo * rsi ;
2168
2178
ErrorContextCallback pl_error_context ;
2169
2179
2170
- /*
2171
- * Create the call_data before connecting to SPI, so that it is not
2172
- * allocated in the SPI memory context
2173
- */
2174
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
2175
- current_call_data -> fcinfo = fcinfo ;
2176
-
2177
2180
if (SPI_connect () != SPI_OK_CONNECT )
2178
2181
elog (ERROR , "could not connect to SPI manager" );
2179
2182
@@ -2286,13 +2289,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
2286
2289
HV * hvTD ;
2287
2290
ErrorContextCallback pl_error_context ;
2288
2291
2289
- /*
2290
- * Create the call_data before connecting to SPI, so that it is not
2291
- * allocated in the SPI memory context
2292
- */
2293
- current_call_data = (plperl_call_data * ) palloc0 (sizeof (plperl_call_data ));
2294
- current_call_data -> fcinfo = fcinfo ;
2295
-
2296
2292
/* Connect to SPI manager */
2297
2293
if (SPI_connect () != SPI_OK_CONNECT )
2298
2294
elog (ERROR , "could not connect to SPI manager" );
0 commit comments