Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f175884

Browse files
committed
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.
1 parent 112c3fc commit f175884

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

contrib/pg_upgrade/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter,
7474
return "can't open source file";
7575

7676
if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
77+
{
78+
fclose(src_fd);
7779
return "can't create destination file";
80+
}
7881

7982
while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ)
8083
{

contrib/pg_upgrade/page.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ getPageVersion(migratorContext *ctx, uint16 *version, const char *pathName)
103103
return "can't open relation";
104104

105105
if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page))
106+
{
107+
close(relfd);
106108
return "can't read page header";
109+
}
107110

108111
*version = PageGetPageLayoutVersion(&page);
109112

0 commit comments

Comments
 (0)