@@ -179,33 +179,29 @@ Datum
179179pg_stat_get_backend_idset (PG_FUNCTION_ARGS )
180180{
181181FmgrInfo * fmgr_info = fcinfo -> flinfo ;
182- MemoryContext oldcxt ;
183182int32 result ;
184183
185- if (fcinfo -> resultinfo == NULL )
186- elog (ERROR ,"called in context that does not accept a set result (1)" );
187- if (!IsA (fcinfo -> resultinfo ,ReturnSetInfo ))
188- elog (ERROR ,"called in context that does not accept a set result (2)" );
184+ if (fcinfo -> resultinfo == NULL ||
185+ !IsA (fcinfo -> resultinfo ,ReturnSetInfo ))
186+ elog (ERROR ,"pg_stat_get_backend_idset: called in context that does not accept a set result" );
189187
190188if (fmgr_info -> fn_extra == NULL )
191189{
192190if (fmgr_info -> fn_mcxt == NULL )
193191elog (ERROR ,"No function memory context in set-function" );
194-
195- oldcxt = MemoryContextSwitchTo (fmgr_info -> fn_mcxt );
196- fmgr_info -> fn_extra = palloc (sizeof (int32 )* 2 );
197- ((int32 * )(fmgr_info -> fn_extra ))[0 ]= 0 ;
198- ((int32 * )(fmgr_info -> fn_extra ))[1 ]=
199- (int32 )pgstat_fetch_stat_numbackends ();
200- MemoryContextSwitchTo (oldcxt );
192+ fmgr_info -> fn_extra = MemoryContextAlloc (fmgr_info -> fn_mcxt ,
193+ 2 * sizeof (int ));
194+ ((int * )(fmgr_info -> fn_extra ))[0 ]= 0 ;
195+ ((int * )(fmgr_info -> fn_extra ))[1 ]= pgstat_fetch_stat_numbackends ();
201196}
202197
203- ((int32 * )(fmgr_info -> fn_extra ))[0 ]+= 1 ;
204- result = ((int32 * )(fmgr_info -> fn_extra ))[0 ];
205-
198+ ((int * )(fmgr_info -> fn_extra ))[0 ]+= 1 ;
199+ result = ((int * )(fmgr_info -> fn_extra ))[0 ];
206200
207- if (result > ((int32 * )(fmgr_info -> fn_extra ))[1 ])
201+ if (result > ((int * )(fmgr_info -> fn_extra ))[1 ])
208202{
203+ pfree (fmgr_info -> fn_extra );
204+ fmgr_info -> fn_extra = NULL ;
209205((ReturnSetInfo * )(fcinfo -> resultinfo ))-> isDone = ExprEndResult ;
210206PG_RETURN_NULL ();
211207}