diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-31 09:00:23 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-31 11:02:21 -0400 |
commit | 776bdc4c5c019a9556a6622a01a406c6c0fec4c9 (patch) | |
tree | b36e3eb7c876f522b1d33f89933e038e29446123 /src/bin/pg_basebackup/streamutil.c | |
parent | 99dd2a390f8b0129092fe62a303b0cd1df547691 (diff) |
Fix memory and file descriptor leaks in pg_receivexlog/pg_basebackup
When the internal loop mode was added, freeing memory and closing
filedescriptors before returning became important, and a few cases
in the code missed that.
This is a backpatch of commit 058a050e to the 9.2 branch, which seems to
have been neglected (in error, because the bugs it fixes were introduced
in commit 16282ae6 which is present in both master and 9.2).
Fujii Masao
Diffstat (limited to 'src/bin/pg_basebackup/streamutil.c')
-rw-r--r-- | src/bin/pg_basebackup/streamutil.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index e5b3ee06c28..96311e07b31 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -143,6 +143,17 @@ GetConnection(void) tmpconn = PQconnectdbParams(keywords, values, true); + /* + * If there is too little memory even to allocate the PGconn object + * and PQconnectdbParams returns NULL, we call exit(1) directly. + */ + if (!tmpconn) + { + fprintf(stderr, _("%s: could not connect to server\n"), + progname); + exit(1); + } + if (PQstatus(tmpconn) == CONNECTION_BAD && PQconnectionNeedsPassword(tmpconn) && dbgetpassword != -1) @@ -154,8 +165,11 @@ GetConnection(void) if (PQstatus(tmpconn) != CONNECTION_OK) { - fprintf(stderr, _("%s: could not connect to server: %s"), + fprintf(stderr, _("%s: could not connect to server: %s\n"), progname, PQerrorMessage(tmpconn)); + PQfinish(tmpconn); + free(values); + free(keywords); return NULL; } |