Skip to content
Snippets Groups Projects
Commit f1758845 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

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.
parent 112c3fc6
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,10 @@ copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter, ...@@ -74,7 +74,10 @@ copyAndUpdateFile(migratorContext *ctx, pageCnvCtx *pageConverter,
return "can't open source file"; return "can't open source file";
if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0) if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
{
fclose(src_fd);
return "can't create destination file"; return "can't create destination file";
}
while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ) while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ)
{ {
......
...@@ -103,7 +103,10 @@ getPageVersion(migratorContext *ctx, uint16 *version, const char *pathName) ...@@ -103,7 +103,10 @@ getPageVersion(migratorContext *ctx, uint16 *version, const char *pathName)
return "can't open relation"; return "can't open relation";
if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page)) if ((bytesRead = read(relfd, &page, sizeof(page))) != sizeof(page))
{
close(relfd);
return "can't read page header"; return "can't read page header";
}
*version = PageGetPageLayoutVersion(&page); *version = PageGetPageLayoutVersion(&page);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment