Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9c5415

Browse files
committed
Fix descriptor leak introduced by bad merge
1 parent8b3ffaa commitc9c5415

File tree

1 file changed

+35
-34
lines changed
  • src/backend/storage/file

1 file changed

+35
-34
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,8 @@ LruDelete(File file)
981981

982982
vfdP=&VfdCache[file];
983983

984+
/* delete the vfd record from the LRU ring */
985+
Delete(file);
984986

985987
if (vfdP->fileFlags&PG_COMPRESSION)
986988
{
@@ -1011,17 +1013,15 @@ LruDelete(File file)
10111013
vfdP->fileName);
10121014
}
10131015

1014-
/*
1015-
* Close the file. We aren't expecting this to fail; if it does, better
1016-
* to leak the FD than to mess up our internal state.
1017-
*/
1018-
if (close(vfdP->fd))
1019-
elog(LOG,"could not close file \"%s\": %m",vfdP->fileName);
1020-
vfdP->fd=VFD_CLOSED;
10211016
--nfile;
10221017
}
1023-
/* delete the vfd record from the LRU ring */
1024-
Delete(file);
1018+
/*
1019+
* Close the file. We aren't expecting this to fail; if it does, better
1020+
* to leak the FD than to mess up our internal state.
1021+
*/
1022+
if (close(vfdP->fd))
1023+
elog(LOG,"could not close file \"%s\": %m",vfdP->fileName);
1024+
vfdP->fd=VFD_CLOSED;
10251025
}
10261026

10271027
staticvoid
@@ -1072,7 +1072,7 @@ LruInsert(File file)
10721072
vfdP->fileMode);
10731073
if (vfdP->fd<0)
10741074
{
1075-
DO_DB(elog(LOG,"re-open failed: %m"));
1075+
DO_DB(elog(LOG,"RE-OPEN FAILED: %m"));
10761076
return-1;
10771077
}
10781078
else
@@ -1107,32 +1107,33 @@ LruInsert(File file)
11071107
else
11081108
{
11091109

1110-
/*
1111-
* Seek to the right position. We need no special case for seekPos
1112-
* equal to FileUnknownPos, as lseek() will certainly reject that
1113-
* (thus completing the logic noted in LruDelete() that we will fail
1114-
* to re-open a file if we couldn't get its seek position before
1115-
* closing).
1116-
*/
1117-
if (vfdP->seekPos!= (off_t)0)
1118-
{
1119-
if (lseek(vfdP->fd,vfdP->seekPos,SEEK_SET)<0)
1110+
/*
1111+
* Seek to the right position. We need no special case for seekPos
1112+
* equal to FileUnknownPos, as lseek() will certainly reject that
1113+
* (thus completing the logic noted in LruDelete() that we will fail
1114+
* to re-open a file if we couldn't get its seek position before
1115+
* closing).
1116+
*/
1117+
if (vfdP->seekPos!= (off_t)0)
11201118
{
1121-
/*
1122-
* If we fail to restore the seek position, treat it like an
1123-
* open() failure.
1124-
*/
1125-
intsave_errno=errno;
1126-
1127-
elog(LOG,"could not seek file \"%s\" after re-opening: %m",
1128-
vfdP->fileName);
1129-
(void)close(vfdP->fd);
1130-
vfdP->fd=VFD_CLOSED;
1131-
--nfile;
1132-
errno=save_errno;
1133-
return-1;
1119+
if (lseek(vfdP->fd,vfdP->seekPos,SEEK_SET)<0)
1120+
{
1121+
/*
1122+
* If we fail to restore the seek position, treat it like an
1123+
* open() failure.
1124+
*/
1125+
intsave_errno=errno;
1126+
1127+
elog(LOG,"could not seek file \"%s\" after re-opening: %m",
1128+
vfdP->fileName);
1129+
(void)close(vfdP->fd);
1130+
vfdP->fd=VFD_CLOSED;
1131+
--nfile;
1132+
errno=save_errno;
1133+
return-1;
1134+
}
11341135
}
1135-
}
1136+
nfile+=1;
11361137
}
11371138
}
11381139

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp