Skip to content

Commit bda1a92

Browse files
committed
Fixed segmentation fault in the dictionary lookup (messing with pointers
in the shared segment while reloading affixes).
1 parent 33508c8 commit bda1a92

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/shared_ispell.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
335335

336336
/* load the dictionary / affixes if not yet defined */
337337
if (shdict == NULL) {
338+
339+
elog(WARNING, "shdict not found");
338340

339341
dict = (IspellDict *)palloc0(sizeof(IspellDict));
340342

@@ -369,8 +371,10 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
369371

370372
} else {
371373

374+
/* local copy, so that we can change the pointers */
375+
SharedIspellDict * shdict_local = NULL;
376+
372377
/* we got the dictionary, but we need to reload the affixes (to handle regex_t rules) */
373-
374378
dict = (IspellDict *)palloc0(sizeof(IspellDict));
375379

376380
NIStartBuild(dict);
@@ -386,6 +390,14 @@ void init_shared_dict(DictInfo * info, char * dictFile, char * affFile, char * s
386390

387391
NIFinishBuild(dict);
388392

393+
/* now, we need to create a local copy of the shared dictionary, so that we can modify the
394+
* pointers locally (without breaking the other backends) */
395+
shdict_local = (SharedIspellDict*)palloc(sizeof(SharedIspellDict));
396+
memcpy(shdict_local, shdict, sizeof(SharedIspellDict));
397+
398+
/* keep the local only */
399+
shdict = shdict_local;
400+
389401
shdict->Suffix = dict->Suffix;
390402
shdict->Prefix = dict->Prefix;
391403

0 commit comments

Comments
 (0)