diff options
author | Magnus Hagander <magnus@hagander.net> | 2012-07-12 13:31:19 +0200 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2012-07-12 13:33:58 +0200 |
commit | 058a050ec769fb1431220d822f00b0a442293514 (patch) | |
tree | 42405cebd7ee34ed8184bb73e7750f7d4e5ab610 /src/bin/pg_basebackup/streamutil.c | |
parent | 84a42560c82aeb9f3690d93a0d03cf544f53b89b (diff) | |
download | postgresql-058a050ec769fb1431220d822f00b0a442293514.tar.gz postgresql-058a050ec769fb1431220d822f00b0a442293514.zip |
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.
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; } |