@@ -97,6 +97,7 @@ plsample_func_handler(PG_FUNCTION_ARGS)
9797 char * proname ;
9898 Form_pg_type pg_type_entry ;
9999 Oid result_typioparam ;
100+ Oid prorettype ;
100101 FmgrInfo result_in_func ;
101102 int numargs ;
102103
@@ -117,7 +118,6 @@ plsample_func_handler(PG_FUNCTION_ARGS)
117118 if (isnull )
118119 elog (ERROR , "could not find source text of function \"%s\"" ,
119120 proname );
120- ReleaseSysCache (pl_tuple );
121121 source = DatumGetCString (DirectFunctionCall1 (textout , ret ));
122122 ereport (NOTICE ,
123123 (errmsg ("source text of function \"%s\": %s" ,
@@ -157,6 +157,10 @@ plsample_func_handler(PG_FUNCTION_ARGS)
157157 i , argnames [i ], value )));
158158 }
159159
160+ /* Type of the result */
161+ prorettype = pl_struct -> prorettype ;
162+ ReleaseSysCache (pl_tuple );
163+
160164 /*
161165 * Get the required information for input conversion of the return value.
162166 *
@@ -165,13 +169,13 @@ plsample_func_handler(PG_FUNCTION_ARGS)
165169 * we can do here. This returns NULL except if the result type is text,
166170 * where the result is the source text of the function.
167171 */
168- if (pl_struct -> prorettype != TEXTOID )
172+ if (prorettype != TEXTOID )
169173 PG_RETURN_NULL ();
170174
171175 type_tuple = SearchSysCache1 (TYPEOID ,
172- ObjectIdGetDatum (pl_struct -> prorettype ));
176+ ObjectIdGetDatum (prorettype ));
173177 if (!HeapTupleIsValid (type_tuple ))
174- elog (ERROR , "cache lookup failed for type %u" , pl_struct -> prorettype );
178+ elog (ERROR , "cache lookup failed for type %u" , prorettype );
175179 pg_type_entry = (Form_pg_type ) GETSTRUCT (type_tuple );
176180 result_typioparam = getTypeIOParam (type_tuple );
177181
0 commit comments