@@ -305,17 +305,32 @@ static SearchPathCacheEntry *LastSearchPathCacheEntry = NULL;
305
305
static void
306
306
spcache_init (void )
307
307
{
308
- Assert (SearchPathCacheContext );
309
-
310
308
if (SearchPathCache && searchPathCacheValid &&
311
309
SearchPathCache -> members < SPCACHE_RESET_THRESHOLD )
312
310
return ;
313
311
314
- /* make sure we don't leave dangling pointers if nsphash_create fails */
312
+ searchPathCacheValid = false;
313
+ baseSearchPathValid = false;
314
+
315
+ /*
316
+ * Make sure we don't leave dangling pointers if a failure happens during
317
+ * initialization.
318
+ */
315
319
SearchPathCache = NULL ;
316
320
LastSearchPathCacheEntry = NULL ;
317
321
318
- MemoryContextReset (SearchPathCacheContext );
322
+ if (SearchPathCacheContext == NULL )
323
+ {
324
+ /* Make the context we'll keep search path cache hashtable in */
325
+ SearchPathCacheContext = AllocSetContextCreate (TopMemoryContext ,
326
+ "search_path processing cache" ,
327
+ ALLOCSET_DEFAULT_SIZES );
328
+ }
329
+ else
330
+ {
331
+ MemoryContextReset (SearchPathCacheContext );
332
+ }
333
+
319
334
/* arbitrary initial starting size of 16 elements */
320
335
SearchPathCache = nsphash_create (SearchPathCacheContext , 16 , NULL );
321
336
searchPathCacheValid = true;
@@ -4742,11 +4757,6 @@ InitializeSearchPath(void)
4742
4757
}
4743
4758
else
4744
4759
{
4745
- /* Make the context we'll keep search path cache hashtable in */
4746
- SearchPathCacheContext = AllocSetContextCreate (TopMemoryContext ,
4747
- "search_path processing cache" ,
4748
- ALLOCSET_DEFAULT_SIZES );
4749
-
4750
4760
/*
4751
4761
* In normal mode, arrange for a callback on any syscache invalidation
4752
4762
* that will affect the search_path cache.
0 commit comments