"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Feb 18, 2022 at 10:59 PM <wliang@stu.xidian.edu.cn> wrote:
>> Specifically, at line 10545 and line 10546, function
>> getFormattedTypeName() is called, which allocates a chunk of memory by
>> using pg_strdup() and returns it.
> I'm not a C programmer but am operating under the assumption that you are
> probably incorrect. So I took a cursory look at the code (in HEAD),
> starting with the function comment. It says:
> "* Note that the result is cached and must not be freed by the caller."
There's also this in the body of the function:
/*
* Cache the result for re-use in later requests, if possible. If we
* don't have a TypeInfo for the type, the string will be leaked once the
* caller is done with it ... but that case really should not happen, so
* leaking if it does seems acceptable.
*/
Since getTypes() makes a TypeInfo for every row of pg_type, "really
should not happen" is an accurate statement. You'd pretty much have to
be dealing with a catalog-corruption scenario for the non-cached path
to be taken.
regards, tom lane