[PATCH] Fix potential memoryleak in guc.c

From: "Zhang, Jie" <zhangjie2(at)cn(dot)fujitsu(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: "Zhang, Jie" <zhangjie2(at)cn(dot)fujitsu(dot)com>
Subject: [PATCH] Fix potential memoryleak in guc.c
Date: 2019-06-10 01:58:48
Message-ID: 1396E95157071C4EBBA51892C5368521017F311ADD@G08CNEXMBPEKD02.g08.fujitsu.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all

In src\backend\utils\misc\guc.c, I found a potential memory leak.

make_absolute_path() return a malloc'd copy, we should free memory before the function return false.
----------------------------------------------------------------------------
SelectConfigFiles(const char *userDoption, const char *progname)
{
......
/* configdir is -D option, or $PGDATA if no -D */
if (userDoption)
configdir = make_absolute_path(userDoption); ★
else
configdir = make_absolute_path(getenv("PGDATA")); ★

if (configdir && stat(configdir, &stat_buf) != 0)
{
write_stderr("%s: could not access directory \"%s\": %s\n",
progname,
configdir,
strerror(errno));
if (errno == ENOENT)
write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n");
★// Need to free memory of configdir
return false;
}
......
---------------------------------------------------------------------------

Refer to the following files for the implementation of make_absolute_path().

file: src\port\path.c
/*
* make_absolute_path
*
* If the given pathname isn't already absolute, make it so, interpreting
* it relative to the current working directory.
*
* Also canonicalizes the path. The result is always a malloc'd copy.

Attachment Content-Type Size
guc.patch application/octet-stream 446 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ian Barwick 2019-06-10 02:06:54 doc: clarify "pg_signal_backend" default role
Previous Message Zhang, Jie 2019-06-10 00:53:49 [PATCH] memory leak in ecpglib