Re: Memory leak in adjust_data_dir
On Wed, 16 Nov 2022 at 12:19, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Japin Li <japinli@hotmail.com> writes:
Hi, hackers,
ITYM pgsql-hackers, this is off-topic here.
Sorry for typo the email address.
When I'm reviewing patch [1], I find there is a memory leak in
adjust_data_dir(), the cmd was allocated by psprintf(), but forget
releasing.Can't get excited about it in pg_ctl; that program won't run
long enough for anybody to notice.
Yeah, it won't run a long time. I find that the memory of my_exec_path
was released, so I think we also should do release on cmd. IMO, this is
a bit confused when should we do release the memory of variables for
short lifetime?
[Here is the origin contents which I send a wrong mail-list]
Hi, hackers,
When I'm reviewing patch [1]/messages/by-id/CALte62y3yZpHNFnYVz1uACaFbmb6go9fyeRaO5uHF5XaxtarbA@mail.gmail.com, I find there is a memory leak in
adjust_data_dir(), the cmd was allocated by psprintf(), but forget
releasing.
[1]: /messages/by-id/CALte62y3yZpHNFnYVz1uACaFbmb6go9fyeRaO5uHF5XaxtarbA@mail.gmail.com
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index ceab603c47..ace2d676fc 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -2159,6 +2159,7 @@ adjust_data_dir(void)
write_stderr(_("%s: could not determine the data directory using command \"%s\"\n"), progname, cmd);
exit(1);
}
+ free(cmd);
free(my_exec_path);
/* strip trailing newline and carriage return */
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.
Import Notes
Reply to msg id not found: 1280390.1668572392@sss.pgh.pa.usReference msg id not found: MEYP282MB16691B0A1A2451F1BFE3EA69B6079@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COMReference msg id not found: 1280390.1668572392@sss.pgh.pa.us