@@ -305,17 +305,32 @@ static SearchPathCacheEntry *LastSearchPathCacheEntry = NULL;
305305static void
306306spcache_init (void )
307307{
308- Assert (SearchPathCacheContext );
309-
310308 if (SearchPathCache && searchPathCacheValid &&
311309 SearchPathCache -> members < SPCACHE_RESET_THRESHOLD )
312310 return ;
313311
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+ */
315319 SearchPathCache = NULL ;
316320 LastSearchPathCacheEntry = NULL ;
317321
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+
319334 /* arbitrary initial starting size of 16 elements */
320335 SearchPathCache = nsphash_create (SearchPathCacheContext , 16 , NULL );
321336 searchPathCacheValid = true;
@@ -4742,11 +4757,6 @@ InitializeSearchPath(void)
47424757 }
47434758 else
47444759 {
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-
47504760 /*
47514761 * In normal mode, arrange for a callback on any syscache invalidation
47524762 * that will affect the search_path cache.
0 commit comments