Skip to content
Snippets Groups Projects
Commit 9835944e authored by Tom Lane's avatar Tom Lane
Browse files

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.
parent b85faa87
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* This should be moved to a more appropriate place. It is here * This should be moved to a more appropriate place. It is here
...@@ -65,6 +65,16 @@ static int cookies_size = 0; ...@@ -65,6 +65,16 @@ static int cookies_size = 0;
static MemoryContext fscxt = NULL; 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 int newLOfd(LargeObjectDesc *lobjCookie);
static void deleteLOfd(int fd); static void deleteLOfd(int fd);
...@@ -87,12 +97,7 @@ lo_open(PG_FUNCTION_ARGS) ...@@ -87,12 +97,7 @@ lo_open(PG_FUNCTION_ARGS)
elog(DEBUG4, "lo_open(%u,%d)", lobjId, mode); elog(DEBUG4, "lo_open(%u,%d)", lobjId, mode);
#endif #endif
if (fscxt == NULL) CreateFSContext();
fscxt = AllocSetContextCreate(TopMemoryContext,
"Filesystem",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
currentContext = MemoryContextSwitchTo(fscxt); currentContext = MemoryContextSwitchTo(fscxt);
...@@ -236,12 +241,7 @@ lo_creat(PG_FUNCTION_ARGS) ...@@ -236,12 +241,7 @@ lo_creat(PG_FUNCTION_ARGS)
MemoryContext currentContext; MemoryContext currentContext;
Oid lobjId; Oid lobjId;
if (fscxt == NULL) CreateFSContext();
fscxt = AllocSetContextCreate(TopMemoryContext,
"Filesystem",
ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE);
currentContext = MemoryContextSwitchTo(fscxt); currentContext = MemoryContextSwitchTo(fscxt);
...@@ -379,6 +379,12 @@ lo_import(PG_FUNCTION_ARGS) ...@@ -379,6 +379,12 @@ lo_import(PG_FUNCTION_ARGS)
errhint("Anyone can use the client-side lo_import() provided by libpq."))); errhint("Anyone can use the client-side lo_import() provided by libpq.")));
#endif #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 * open the file to be read in
*/ */
...@@ -446,6 +452,12 @@ lo_export(PG_FUNCTION_ARGS) ...@@ -446,6 +452,12 @@ lo_export(PG_FUNCTION_ARGS)
errhint("Anyone can use the client-side lo_export() provided by libpq."))); errhint("Anyone can use the client-side lo_export() provided by libpq.")));
#endif #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) * open the inversion object (no need to test for failure)
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment