8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.74 2004/08/29 05:06:43 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.75 2004/09/11 15:56:46 tgl Exp $
12
12
*
13
13
* NOTES
14
14
* This should be moved to a more appropriate place. It is here
@@ -65,6 +65,16 @@ static int cookies_size = 0;
65
65
66
66
static MemoryContext fscxt = NULL ;
67
67
68
+ #define CreateFSContext () \
69
+ do { \
70
+ if (fscxt == NULL) \
71
+ fscxt = AllocSetContextCreate(TopMemoryContext, \
72
+ "Filesystem", \
73
+ ALLOCSET_DEFAULT_MINSIZE, \
74
+ ALLOCSET_DEFAULT_INITSIZE, \
75
+ ALLOCSET_DEFAULT_MAXSIZE); \
76
+ } while (0)
77
+
68
78
69
79
static int newLOfd (LargeObjectDesc * lobjCookie );
70
80
static void deleteLOfd (int fd );
@@ -87,12 +97,7 @@ lo_open(PG_FUNCTION_ARGS)
87
97
elog (DEBUG4 , "lo_open(%u,%d)" , lobjId , mode );
88
98
#endif
89
99
90
- if (fscxt == NULL )
91
- fscxt = AllocSetContextCreate (TopMemoryContext ,
92
- "Filesystem" ,
93
- ALLOCSET_DEFAULT_MINSIZE ,
94
- ALLOCSET_DEFAULT_INITSIZE ,
95
- ALLOCSET_DEFAULT_MAXSIZE );
100
+ CreateFSContext ();
96
101
97
102
currentContext = MemoryContextSwitchTo (fscxt );
98
103
@@ -236,12 +241,7 @@ lo_creat(PG_FUNCTION_ARGS)
236
241
MemoryContext currentContext ;
237
242
Oid lobjId ;
238
243
239
- if (fscxt == NULL )
240
- fscxt = AllocSetContextCreate (TopMemoryContext ,
241
- "Filesystem" ,
242
- ALLOCSET_DEFAULT_MINSIZE ,
243
- ALLOCSET_DEFAULT_INITSIZE ,
244
- ALLOCSET_DEFAULT_MAXSIZE );
244
+ CreateFSContext ();
245
245
246
246
currentContext = MemoryContextSwitchTo (fscxt );
247
247
@@ -379,6 +379,12 @@ lo_import(PG_FUNCTION_ARGS)
379
379
errhint ("Anyone can use the client-side lo_import() provided by libpq." )));
380
380
#endif
381
381
382
+ /*
383
+ * We don't actually need to switch into fscxt, but create it anyway
384
+ * to ensure that AtEOXact_LargeObject knows there is state to clean up
385
+ */
386
+ CreateFSContext ();
387
+
382
388
/*
383
389
* open the file to be read in
384
390
*/
@@ -446,6 +452,12 @@ lo_export(PG_FUNCTION_ARGS)
446
452
errhint ("Anyone can use the client-side lo_export() provided by libpq." )));
447
453
#endif
448
454
455
+ /*
456
+ * We don't actually need to switch into fscxt, but create it anyway
457
+ * to ensure that AtEOXact_LargeObject knows there is state to clean up
458
+ */
459
+ CreateFSContext ();
460
+
449
461
/*
450
462
* open the inversion object (no need to test for failure)
451
463
*/
0 commit comments