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], I find there is a memory leak in
adjust_data_dir(), the cmd was allocated by psprintf(), but forget
releasing.
[1] https://www.postgresql.org/message-id/CALte62y3yZpHNFnYVz1uACaFbmb6go9fyeRaO5uHF5XaxtarbA%40mail.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.