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

Commit4598a99

Browse files
committed
Make get_controlfile not leak file descriptors
When backend functions were added to expose controldata via SQL,reading of pg_control was consolidated under src/common so thatboth frontend and backend could share the same code. That movefrom frontend-only to shared frontend-backend failed to recognizethe risk (and coding standards violation) of using a bare open().In particular, it risked leaking file descriptors if transienterrors occurred while reading the file. Fix that by usingOpenTransientFile() instead in the backend case, which ispurpose-built for this type of usage.Since there have been no complaints from the field, and an intermittentfailure low risk, no backpatch. Hard failure would of course be bad, butin that case these functions are probably the least of your worries.Author: Joe ConwayReviewed-By: Michael PaquierReported by: Michael PaquierDiscussion:https://postgr.es/m/20190227074728.GA15710@paquier.xyz
1 parentf414abd commit4598a99

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/common/controldata_utils.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include"catalog/pg_control.h"
2828
#include"common/controldata_utils.h"
2929
#include"port/pg_crc32c.h"
30+
#ifndefFRONTEND
31+
#include"storage/fd.h"
32+
#endif
3033

3134
/*
32-
* get_controlfile(char *DataDir, const char *progname, bool *crc_ok_p)
35+
* get_controlfile()
3336
*
3437
* Get controlfile values. The result is returned as a palloc'd copy of the
3538
* control file data.
@@ -51,13 +54,14 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
5154
ControlFile=palloc(sizeof(ControlFileData));
5255
snprintf(ControlFilePath,MAXPGPATH,"%s/global/pg_control",DataDir);
5356

54-
if ((fd=open(ControlFilePath,O_RDONLY |PG_BINARY,0))==-1)
5557
#ifndefFRONTEND
58+
if ((fd=OpenTransientFile(ControlFilePath,O_RDONLY |PG_BINARY))==-1)
5659
ereport(ERROR,
5760
(errcode_for_file_access(),
5861
errmsg("could not open file \"%s\" for reading: %m",
5962
ControlFilePath)));
6063
#else
64+
if ((fd=open(ControlFilePath,O_RDONLY |PG_BINARY,0))==-1)
6165
{
6266
fprintf(stderr,_("%s: could not open file \"%s\" for reading: %s\n"),
6367
progname,ControlFilePath,strerror(errno));
@@ -95,7 +99,11 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
9599
#endif
96100
}
97101

102+
#ifndefFRONTEND
103+
CloseTransientFile(fd);
104+
#else
98105
close(fd);
106+
#endif
99107

100108
/* Check the CRC. */
101109
INIT_CRC32C(crc);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp