@@ -283,11 +283,15 @@ clean_dict_affix(IspellDict *dict)
283
283
* of the shared memory (using SegmentInfo->lock).
284
284
*/
285
285
static 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 )
287
288
{
288
289
int size ;
289
290
SharedIspellDict * shdict = NULL ;
290
291
SharedStopList * shstop = NULL ;
292
+ MemoryContext oldctx ;
293
+
294
+ oldctx = MemoryContextSwitchTo (infoCntx );
291
295
292
296
/* DICTIONARY + AFFIXES */
293
297
@@ -413,8 +417,9 @@ init_shared_dict(DictInfo *info, char *dictFile, char *affFile, char *stopFile)
413
417
else
414
418
memset (info -> stopFile , 0 , sizeof (info -> stopFile ));
415
419
420
+ MemoryContextSwitchTo (oldctx );
416
421
/* save current context as long-lived */
417
- info -> saveCntx = CurrentMemoryContext ;
422
+ info -> infoCntx = infoCntx ;
418
423
}
419
424
420
425
Datum dispell_init (PG_FUNCTION_ARGS );
@@ -576,7 +581,15 @@ dispell_init(PG_FUNCTION_ARGS)
576
581
/* search if the dictionary is already initialized */
577
582
LWLockAcquire (segment_info -> lock , LW_EXCLUSIVE );
578
583
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 );
580
593
581
594
LWLockRelease (segment_info -> lock );
582
595
@@ -605,8 +618,7 @@ dispell_lexize(PG_FUNCTION_ARGS)
605
618
/* do we need to reinit the dictionary? was the dict reset since the lookup */
606
619
if (timestamp_cmp_internal (info -> lookup , segment_info -> lastReset ) < 0 )
607
620
{
608
- DictInfo saveInfo = * info ;
609
- MemoryContext ctx ;
621
+ DictInfo saveInfo = * info ;
610
622
611
623
/* relock in exclusive mode */
612
624
LWLockRelease (segment_info -> lock );
@@ -617,15 +629,11 @@ dispell_lexize(PG_FUNCTION_ARGS)
617
629
* info here
618
630
*/
619
631
620
- MemoryContextResetAndDeleteChildren (saveInfo .saveCntx );
621
- ctx = MemoryContextSwitchTo (saveInfo .saveCntx );
622
-
632
+ MemoryContextResetAndDeleteChildren (saveInfo .infoCntx );
623
633
MemSet (info , 0 , sizeof (* info ));
624
634
625
- init_shared_dict (info , saveInfo .dictFile ,
635
+ init_shared_dict (info , saveInfo .infoCntx , saveInfo . dictFile ,
626
636
saveInfo .affixFile , saveInfo .stopFile );
627
-
628
- MemoryContextSwitchTo (ctx );
629
637
}
630
638
631
639
res = NINormalizeWord (& (info -> dict ), txt );
0 commit comments