Worth mentioning that this is intended for descriptors not managed by another cleanup mechanism, such as those returned by BasicOpenFile()? Otherwise, using it with OpenTransientFile() could result in segment_close() being called with a stale descriptor.
BasicOpenFile() called repeatedly will accumulate stale descriptors indefinitely.
int BasicOpenFile(const char *fileName, int fileFlags) { return BasicOpenFilePerm(fileName, fileFlags, pg_file_create_mode); }
int BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)