]> granicus.if.org Git - postgresql/commitdiff
Be sure to close() file descriptor on error case
authorStephen Frost <sfrost@snowman.net>
Sun, 14 Jul 2013 21:25:47 +0000 (17:25 -0400)
committerStephen Frost <sfrost@snowman.net>
Sun, 14 Jul 2013 21:25:47 +0000 (17:25 -0400)
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.

src/bin/pg_basebackup/receivelog.c

index 7ce81125bfe692cdc5b1ea7d63ffa4d3e0b37d9a..d56a4d71ea2e71c5f0237cea1ed34f3fe6feee11 100644 (file)
@@ -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;