postgresql/src/backend/utils
Heikki Linnakangas 1f67078ea3 Add OpenTransientFile, with automatic cleanup at end-of-xact.
Files opened with BasicOpenFile or PathNameOpenFile are not automatically
cleaned up on error. That puts unnecessary burden on callers that only want
to keep the file open for a short time. There is AllocateFile, but that
returns a buffered FILE * stream, which in many cases is not the nicest API
to work with. So add function called OpenTransientFile, which returns a
unbuffered fd that's cleaned up like the FILE* returned by AllocateFile().

This plugs a few rare fd leaks in error cases:

1. copy_file() - fixed by by using OpenTransientFile instead of BasicOpenFile
2. XLogFileInit() - fixed by adding close() calls to the error cases. Can't
   use OpenTransientFile here because the fd is supposed to persist over
   transaction boundaries.
3. lo_import/lo_export - fixed by using OpenTransientFile instead of
   PathNameOpenFile.

In addition to plugging those leaks, this replaces many BasicOpenFile() calls
with OpenTransientFile() that were not leaking, because the code meticulously
closed the file on error. That wasn't strictly necessary, but IMHO it's good
for robustness.

The same leaks exist in older versions, but given the rarity of the issues,
I'm not backpatching this. Not yet, anyway - it might be good to backpatch
later, after this mechanism has had some more testing in master branch.
2012-11-27 10:25:50 +02:00
..
adt Speed up operations on numeric, mostly by avoiding palloc() overhead. 2012-11-21 15:53:35 +02:00
cache Add OpenTransientFile, with automatic cleanup at end-of-xact. 2012-11-27 10:25:50 +02:00
error Use correct text domain for translating errcontext() messages. 2012-11-12 17:07:29 +02:00
fmgr Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
hash Fix hash_search to avoid corruption of the hash table on out-of-memory. 2012-10-19 15:24:03 -04:00
init Parse pg_ident.conf when it's loaded, keeping it in memory in parsed format. 2012-09-21 17:54:39 +03:00
mb Remove configure flag --disable-shared, as it is no longer used by any 2012-08-30 16:26:53 -04:00
misc Limit values of archive_timeout, post_auth_delay, auth_delay.milliseconds. 2012-11-18 17:15:06 -05:00
mmgr Fix thinko in previous commit 2012-10-08 18:33:08 -03:00
resowner Split resowner.h 2012-08-28 18:02:07 -04:00
sort Add support for easily declaring static inline functions 2012-10-08 16:28:01 -03:00
time Split tuple struct defs from htup.h to htup_details.h 2012-08-30 16:52:35 -04:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Code review for 64-bit-large-object patch. 2012-10-08 18:24:32 -04:00
Gen_dummy_probes.sed Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
Gen_fmgrtab.pl Run updated copyright.pl on HEAD and 9.2 trees, updating the psql 2012-07-06 12:28:18 -04:00
generate-errcodes.pl Run newly-configured perltidy script on Perl files. 2012-07-04 21:47:49 -04:00
Makefile Make handling of errcodes.h more consistent with other generated headers. 2011-02-04 09:29:10 -05:00
probes.d Make group commit more effective. 2012-01-30 16:53:48 +02:00