@@ -283,11 +283,15 @@ clean_dict_affix(IspellDict *dict)
283283 * of the shared memory (using SegmentInfo->lock).
284284 */
285285static void
286- init_shared_dict (DictInfo * info , char * dictFile , char * affFile , char * stopFile )
286+ init_shared_dict (DictInfo * info , MemoryContext infoCntx ,
287+ char * dictFile , char * affFile , char * stopFile )
287288{
288289 int size ;
289290 SharedIspellDict * shdict = NULL ;
290291 SharedStopList * shstop = NULL ;
292+ MemoryContext oldctx ;
293+
294+ oldctx = MemoryContextSwitchTo (infoCntx );
291295
292296 /* DICTIONARY + AFFIXES */
293297
@@ -413,8 +417,9 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
413417 else
414418 memset (info -> stopFile , 0 , sizeof (info -> stopFile ));
415419
420+ MemoryContextSwitchTo (oldctx );
416421 /* save current context as long-lived */
417- info -> saveCntx = CurrentMemoryContext ;
422+ info -> infoCntx = infoCntx ;
418423}
419424
420425Datum dispell_init (PG_FUNCTION_ARGS );
@@ -576,7 +581,15 @@ dispell_init(PG_FUNCTION_ARGS)
576581 /* search if the dictionary is already initialized */
577582 LWLockAcquire (segment_info -> lock , LW_EXCLUSIVE );
578583
579- init_shared_dict (info , dictFile , affFile , stopFile );
584+ /*
585+ * Current context is a long lived context. Create child context to store
586+ * DictInfo internal data.
587+ */
588+ info -> infoCntx = AllocSetContextCreate (CurrentMemoryContext ,
589+ "shared_ispell context" ,
590+ ALLOCSET_DEFAULT_SIZES );
591+
592+ init_shared_dict (info , info -> infoCntx , dictFile , affFile , stopFile );
580593
581594 LWLockRelease (segment_info -> lock );
582595
@@ -605,8 +618,7 @@ dispell_lexize(PG_FUNCTION_ARGS)
605618 /* do we need to reinit the dictionary? was the dict reset since the lookup */
606619 if (timestamp_cmp_internal (info -> lookup , segment_info -> lastReset ) < 0 )
607620 {
608- DictInfo saveInfo = * info ;
609- MemoryContext ctx ;
621+ DictInfo saveInfo = * info ;
610622
611623 /* relock in exclusive mode */
612624 LWLockRelease (segment_info -> lock );
@@ -617,15 +629,11 @@ dispell_lexize(PG_FUNCTION_ARGS)
617629 * info here
618630 */
619631
620- MemoryContextResetAndDeleteChildren (saveInfo .saveCntx );
621- ctx = MemoryContextSwitchTo (saveInfo .saveCntx );
622-
632+ MemoryContextResetAndDeleteChildren (saveInfo .infoCntx );
623633 MemSet (info , 0 , sizeof (* info ));
624634
625- init_shared_dict (info , saveInfo .dictFile ,
635+ init_shared_dict (info , saveInfo .infoCntx , saveInfo . dictFile ,
626636 saveInfo .affixFile , saveInfo .stopFile );
627-
628- MemoryContextSwitchTo (ctx );
629637 }
630638
631639 res = NINormalizeWord (& (info -> dict ), txt );
0 commit comments