diff options
author | Bruce Momjian <bruce@momjian.us> | 2010-09-28 19:25:13 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2010-09-28 19:25:13 +0000 |
commit | c767c3bd3690aa06a7965d7f9f9d80e5c15174cd (patch) | |
tree | 276eb5bcc89a97e658d6a158f847eb473589453b | |
parent | 3fe9f0e5c734c79b604abfdfd3766e85c1e4b2b7 (diff) |
Properly close files after read file failure to prevent potential
resource leak. Of course, any such failure aborts pg_upgrade, but might
as well be clean about it.
Per patch from Grzegorz Ja?kiewicz.
-rw-r--r-- | contrib/pg_upgrade/file.c | 3 | ||||
-rw-r--r-- | contrib/pg_upgrade/page.c | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c index 358fcf51b5a..ef797037fb1 100644 --- a/contrib/pg_upgrade/file.c +++ b/contrib/pg_upgrade/file.c @@ -74,7 +74,10 @@ copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter, return "can't open source file"; if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0) + { + fclose(src_fd); return "can't create destination file"; + } while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ) { diff --git a/contrib/pg_upgrade/page.c b/contrib/pg_upgrade/page.c index de19a0023e0..4b8a9390f3f 100644 --- a/contrib/pg_upgrade/page.c +++ b/contrib/pg_upgrade/page.c @@ -103,7 +103,10 @@ getPageVersion(migratorContext *ctx, uint16 *version, const char *pathName) return "can't open relation"; if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page)) + { + close(relfd); return "can't read page header"; + } *version = PageGetPageLayoutVersion(&page); |