aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-11 15:56:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-11 15:56:46 +0000
commit9835944e54ace63b040d2d2e78eaa0b78aca1bed (patch)
tree68649f0337e3040f6fba5dc311c42410415c0222 /src
parentb85faa87b9a0961283ee55bad877ff0853c93dd8 (diff)
downloadpostgresql-9835944e54ace63b040d2d2e78eaa0b78aca1bed.tar.gz
postgresql-9835944e54ace63b040d2d2e78eaa0b78aca1bed.zip
Ensure that pg_largeobject references opened by lo_import() or lo_export()
will be cleaned up at end of transaction, even when there is no other LO operation in the transaction. Per bug report from Daniel Schuchardt.
Diffstat (limited to 'src')
-rw-r--r--src/backend/libpq/be-fsstubs.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 23244d8fdb5..b059c05240a 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.74 2004/08/29 05:06:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.75 2004/09/11 15:56:46 tgl Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
@@ -65,6 +65,16 @@ static int cookies_size = 0;
static MemoryContext fscxt = NULL;
+#define CreateFSContext() \
+ do { \
+ if (fscxt == NULL) \
+ fscxt = AllocSetContextCreate(TopMemoryContext, \
+ "Filesystem", \
+ ALLOCSET_DEFAULT_MINSIZE, \
+ ALLOCSET_DEFAULT_INITSIZE, \
+ ALLOCSET_DEFAULT_MAXSIZE); \
+ } while (0)
+
static int newLOfd(LargeObjectDesc *lobjCookie);
static void deleteLOfd(int fd);
@@ -87,12 +97,7 @@ lo_open(PG_FUNCTION_ARGS)
elog(DEBUG4, "lo_open(%u,%d)", lobjId, mode);
#endif
- if (fscxt == NULL)
- fscxt = AllocSetContextCreate(TopMemoryContext,
- "Filesystem",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ CreateFSContext();
currentContext = MemoryContextSwitchTo(fscxt);
@@ -236,12 +241,7 @@ lo_creat(PG_FUNCTION_ARGS)
MemoryContext currentContext;
Oid lobjId;
- if (fscxt == NULL)
- fscxt = AllocSetContextCreate(TopMemoryContext,
- "Filesystem",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ CreateFSContext();
currentContext = MemoryContextSwitchTo(fscxt);
@@ -380,6 +380,12 @@ lo_import(PG_FUNCTION_ARGS)
#endif
/*
+ * We don't actually need to switch into fscxt, but create it anyway
+ * to ensure that AtEOXact_LargeObject knows there is state to clean up
+ */
+ CreateFSContext();
+
+ /*
* open the file to be read in
*/
nbytes = VARSIZE(filename) - VARHDRSZ;
@@ -447,6 +453,12 @@ lo_export(PG_FUNCTION_ARGS)
#endif
/*
+ * We don't actually need to switch into fscxt, but create it anyway
+ * to ensure that AtEOXact_LargeObject knows there is state to clean up
+ */
+ CreateFSContext();
+
+ /*
* open the inversion object (no need to test for failure)
*/
lobj = inv_open(lobjId, INV_READ);