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 1jMGLH-0002Lv-CU for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Apr 2020 19:26:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMGKi-0006l0-Rw for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Apr 2020 19:25:56 +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 1jMGKi-0006jL-LM for pgsql-bugs@lists.postgresql.org; Wed, 08 Apr 2020 19:25:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMGKf-0004FG-6I for pgsql-bugs@lists.postgresql.org; Wed, 08 Apr 2020 19:25:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 038JPnnm004654; Wed, 8 Apr 2020 15:25:50 -0400 From: Tom Lane To: Hugh Wang cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16348: Memory leak when parsing config In-reply-to: References: <16348-018c10b6fd16ebcc@postgresql.org> <29582.1586272948@sss.pgh.pa.us> Comments: In-reply-to Hugh Wang message dated "Wed, 08 Apr 2020 06:51:14 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4652.1586373949.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 08 Apr 2020 15:25:49 -0400 Message-ID: <4653.1586373949@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hugh Wang writes: > Even if I believe in LeakSanitizer, it's absolutely stupid to ignore the > recommendations from an experienced developer. To really make sure that = there's > memory leak, I verified the leak with gdb. When ProcessConfigFile is ent= ered, I > set a breakpoint to print guc_strdup's return value ($rax) in > set_config_sourcefile. I also set a breakpoint on free to print the argu= ment > ($rdi). To sum up: for any returned pointer ofguc_strdup, if a > corresponding free > cannot be found, then we can confirm that there's a leak. [ shrug... ] Nonetheless, your analysis is faulty, because it's experimentally demonstrable that there is no leak. I just left a backend run for quite some time, hitting it with a stream of SIGHUPs, and for good measure having it read the pg_file_settings view over and over so that the show_all_file_settings code path is being exercised as well. By now, if either of those code paths was leaking even one single byte per execution, I could see the difference in "top". But the process memory size is not moving. I speculate that you may be confusing the transient ConfigVariable data structures with the non-transient GUC storage (struct config_generic and its overlays). The former data structure, including attached strings such as filenames, is palloc'd in a short-lived memory context and we get rid of it by dropping the context. The actual GUC storage is malloc'd so we have to take care to free() any string we replace. As far as I can tell, we do. set_config_sourcefile certainly does so. regards, tom lane