Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLJn9-0001jb-Eg for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Feb 2022 07:04:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nLJn8-000224-9Q for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Feb 2022 07:04:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLJn8-00021v-1H for pgsql-bugs@lists.postgresql.org; Sat, 19 Feb 2022 07:04:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLJn0-0006Tz-Ra for pgsql-bugs@lists.postgresql.org; Sat, 19 Feb 2022 07:04:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 21J74Et5012082; Sat, 19 Feb 2022 02:04:14 -0500 From: Tom Lane To: "David G. Johnston" cc: wliang@stu.xidian.edu.cn, pgsql-bugs Subject: Re: Report some potential memory leak bugs in pg_dump.c In-reply-to: References: <41c0d83b.acf.17f1083ab65.Coremail.wliang@stu.xidian.edu.cn> Comments: In-reply-to "David G. Johnston" message dated "Fri, 18 Feb 2022 23:15:55 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12080.1645254254.1@sss.pgh.pa.us> Date: Sat, 19 Feb 2022 02:04:14 -0500 Message-ID: <12081.1645254254@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Fri, Feb 18, 2022 at 10:59 PM 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