aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/receivelog.c
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2013-07-14 17:30:43 -0400
committerStephen Frost <sfrost@snowman.net>2013-07-14 17:30:43 -0400
commitcec62efd0e551a56635b47ea4185ec27a6840de7 (patch)
treefbc7e07f03a7ca64f4b61e65498a507ef93bfb66 /src/bin/pg_basebackup/receivelog.c
parent273dcd16282c8014a14a9ecbf467459b8702e745 (diff)
downloadpostgresql-cec62efd0e551a56635b47ea4185ec27a6840de7.tar.gz
postgresql-cec62efd0e551a56635b47ea4185ec27a6840de7.zip
Be sure to close() file descriptor on error case
In receivelog.c:writeTimeLineHistoryFile(), we were not properly closing the open'd file descriptor in error cases. While this wouldn't matter much if we were about to exit due to such an error, that's not the case with pg_receivexlog as it can be a long-running process and these errors are non-fatal. This resource leak was found by the Coverity scanner. Back-patch to 9.3 where this issue first appeared.
Diffstat (limited to 'src/bin/pg_basebackup/receivelog.c')
-rw-r--r--src/bin/pg_basebackup/receivelog.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 7ce81125bfe..d56a4d71ea2 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -329,6 +329,7 @@ writeTimeLineHistoryFile(char *basedir, TimeLineID tli, char *filename, char *co
/*
* If we fail to make the file, delete it to release disk space
*/
+ close(fd);
unlink(tmppath);
errno = save_errno;
@@ -339,6 +340,7 @@ writeTimeLineHistoryFile(char *basedir, TimeLineID tli, char *filename, char *co
if (fsync(fd) != 0)
{
+ close(fd);
fprintf(stderr, _("%s: could not fsync file \"%s\": %s\n"),
progname, tmppath, strerror(errno));
return false;