summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-16 20:32:35 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-16 20:32:35 -0500
commitd726e44fb9c0a8e3c0f405b88d28d55ece1837c6 (patch)
treef1c079f82dc509203fed170419ff76f30ebd5ee7 /src
parentde56e96ac83d2745566d36fd03617561ee026a2b (diff)
Don't Insert() a VFD entry until it's fully built.
Otherwise, if FDDEBUG is enabled, the debugging output fails because it tries to read the fileName, which isn't set up yet (and should in fact always be NULL). AFAICT, this has been wrong since Berkeley. Before 96bf88d52, it would accidentally fail to crash on platforms where snprintf() is forgiving about being passed a NULL pointer for %s; but the file name intended to be included in the debug output wouldn't ever have shown up. Report and fix by Greg Nancarrow. Although this is only visibly broken in custom-made builds, it still seems worth back-patching to all supported branches, as the FDDEBUG code is pretty useless as it stands. Discussion: https://postgr.es/m/CAJcOf-cUDgm9qYtC_B6XrC6MktMPNRby2p61EtSGZKnfotMArw@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/fd.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 03d43fdada1..7fa6fc996dc 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1323,8 +1323,6 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
DO_DB(elog(LOG, "PathNameOpenFile: success %d",
vfdP->fd));
- Insert(file);
-
vfdP->fileName = fnamecopy;
/* Saved flags are adjusted to be OK for re-opening file */
vfdP->fileFlags = fileFlags & ~(O_CREAT | O_TRUNC | O_EXCL);
@@ -1334,6 +1332,8 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
vfdP->fdstate = 0x0;
vfdP->resowner = NULL;
+ Insert(file);
+
return file;
}