pgsql: Fix inconsequential FILE pointer leakage

Started by Alvaro Herreraover 15 years ago3 messagescomitters
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

Fix inconsequential FILE pointer leakage

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=83c759ea0ea8ffe07c45e6fd2c489cebce2caad6

Modified Files
--------------
src/port/exec.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#1)
Re: pgsql: Fix inconsequential FILE pointer leakage

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

--- a/src/port/exec.c
+++ b/src/port/exec.c
@@ -357,6 +357,7 @@ pipe_read_line(char *cmd, char *line, int maxsize)

if (fgets(line, maxsize, pgver) == NULL)
{
+ pclose(pgver); /* no error checking */
perror("fgets failure");
return NULL;
}

Doesn't this risk having pclose trash the errno setting that perror is
going to print? If you must do this, please do it in the other order.

regards, tom lane

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: pgsql: Fix inconsequential FILE pointer leakage

Excerpts from Tom Lane's message of jue dic 16 17:00:43 -0300 2010:

--- a/src/port/exec.c
+++ b/src/port/exec.c
@@ -357,6 +357,7 @@ pipe_read_line(char *cmd, char *line, int maxsize)

if (fgets(line, maxsize, pgver) == NULL)
{
+ pclose(pgver); /* no error checking */
perror("fgets failure");
return NULL;
}

Doesn't this risk having pclose trash the errno setting that perror is
going to print? If you must do this, please do it in the other order.

Gah, yes, sorry. Fixed.

--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support