Re: Report some potential memory leak bugs in pg_dump.c - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Report some potential memory leak bugs in pg_dump.c
Date
Msg-id 12081.1645254254@sss.pgh.pa.us
Whole thread Raw
In response to Re: Report some potential memory leak bugs in pg_dump.c  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"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



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Report some potential memory leak bugs in pg_dump.c
Next
From: wliang@stu.xidian.edu.cn
Date:
Subject: Re all: Report some potential memory leak bugs in pg_dump.c