From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: wliang@stu.xidian.edu.cn, pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: Re: Report some potential memory leak bugs in pg_dump.c
Date: Sat, 19 Feb 2022 02:04:14 -0500
Message-ID: <12081.1645254254@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYK9NOENP=cQdvnmZcN0nxaWDWySQ4RT5_opbr5MAMihQ@mail.gmail.com>
References: <41c0d83b.acf.17f1083ab65.Coremail.wliang@stu.xidian.edu.cn>
<CAKFQuwYK9NOENP=cQdvnmZcN0nxaWDWySQ4RT5_opbr5MAMihQ@mail.gmail.com>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Report some potential memory leak bugs in pg_dump.c
In-Reply-To: <12081.1645254254@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox