Skip to content

Commit 8b55719

Browse files
committed
fa70830 isn't correct.
Fix the bug by creating child context of entry->dictCtx.
1 parent fa70830 commit 8b55719

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ endif
2323

2424
# Disabled because these tests require "shared_preload_libraries=shared_ispell",
2525
# which typical installcheck users do not have (e.g. buildfarm clients).
26-
installcheck: REGRESS=
26+
#installcheck: REGRESS=

src/shared_ispell.c

+19-11
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,15 @@ clean_dict_affix(IspellDict *dict)
283283
* of the shared memory (using SegmentInfo->lock).
284284
*/
285285
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)
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

420425
Datum 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);

src/shared_ispell.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef struct DictInfo
6969
SharedStopList *shstop;
7070

7171
/* MemoryContext of dict local content */
72-
MemoryContext saveCntx;
72+
MemoryContext infoCntx;
7373
} DictInfo;
7474

7575
#endif

0 commit comments

Comments
 (0)