Fix file descriptor leakages in pg_waldump. TarWALDumpCloseSegment was of the opinion that it didn't need to do anything. It was mistaken: it has to close the open file if any, because nothing else will, leading to a descriptor leak.
In addition, we failed to ensure that any file being read by the XLogReader machinery gets closed before the atexit callback tries to cleanup the temporary directory holding spilled WAL files. While the file would have been closed already in case of a success exit, this doesn't happen in case of pg_fatal() exits. The least messy way to fix that is to move the atexit function into pg_waldump.c, where it has easier access to the XLogReaderState pointer and to WALDumpCloseSegment. These FD leakages are pretty insignificant on Unix-ish platforms, but they're a bug on Windows, because they prevent successful cleanup of the temporary directory for extracted WAL files. (Windows can't delete a directory that holds a deleted-but-still-open file.) This is visible in occasional buildfarm failures. This code's all new as of commit b15c15139, so no need for back-patch. Discussion: https://postgr.es/m/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/03b1e30e7aa5c0d83514db4156cfc80632f50493 Modified Files -------------- src/bin/pg_waldump/archive_waldump.c | 26 +++------------------ src/bin/pg_waldump/pg_waldump.c | 44 +++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 26 deletions(-)
