Skip to content

Closing one engine no longer breaks another in the same process (#791) (4.2.35) - #792

Merged
ddehilster merged 2 commits into
masterfrom
fix/engine-gstab-791
Oct 15, 2026
Merged

ddehilster merged 2 commits into
masterfrom
fix/engine-gstab-791

Conversation

@ddehilster

Copy link
Copy Markdown
Member

Closes #791.

Cause. Analyzer loading interns rule and function names (rule-element hash tables, rule tables, user-function tables) into Htab::gstab_, the process-wide default string table. Each VTRun set gstab_ only once, when it was created. So with two NLP_ENGINEs open, the one created last owned every analyzer's names, including those of analyzers the first engine loaded afterwards. Closing it freed them, and the first engine's next analyze() read freed memory: it crashed or returned nothing. AddressSanitizer (MSVC /fsanitize=address) reported the bad read in Stab::currSize ← Ifunc::loadHtab ← NLP::make_analyzer.

It shows up in NLPPlus: set_working_folder() and the test suite open several engines. VisualText/py-package-nlpengine#46 worked around it on the Python side.

Fix.

  • VTRun::useStab() makes a runtime's own table the default.
  • Every NLP_ENGINE entry point (init, the three analyze overloads, analyzeStream) calls it first.
  • VTRun::clear() resets the default to null if it pointed at the table being freed, so nothing is left dangling.
  • No API or class-layout change: one new non-virtual method.

Regression test. test-nlp (test/main.cpp) gets a two-engine check. It opens an engine, opens a second, has the first load an analyzer while the second is the newest, closes the second, then analyzes with the first. It fails on master ("engine broken after closing another, cycle 0") and passes with the fix. The new Windows CI step builds and runs test-nlp, which CI never ran before.

Tests:

  • C++ repro under AddressSanitizer: errors before the fix, zero errors after, over 4 cycles with a shared working folder and 8 with separate ones.
  • Local: 48/49 CI steps pass. The compiled-bridge step needs $GITHUB_WORKSPACE and always fails locally.
  • Full English Test: unchanged.
  • 20 analyzers × 21 inputs: 0 differences.

After this releases, NLPPlus's one-engine-at-a-time workaround stays harmless, and Python users can safely hold several Engines.

🤖 Generated with Claude Code

ddehilster and others added 2 commits October 15, 2026 12:59
… (4.2.35)

Analyzer loading interns rule and function names into Htab::gstab_, the
process-wide default string table. Each VTRun set it only when made, so
with two NLP_ENGINEs open the one made last owned every analyzer's names;
closing it freed them, and the other engine's next analyze() crashed or
returned nothing. Found through NLPPlus, where set_working_folder and the
test suite open several engines; AddressSanitizer showed the reads.

Every NLP_ENGINE entry point (init, analyze, analyzeStream) now makes its
own runtime's table the default first (VTRun::useStab), and a runtime
being deleted clears the default if it pointed at its table.

test-nlp gains a two-engine check, run in Windows CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Windows job checks out VisualText/analyzers near its end; before
that, analyzers/parse-en-us has no spec and test-nlp could not build it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddehilster
ddehilster merged commit e97a3b0 into master Oct 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closing one NLP_ENGINE breaks another still open in the same process

1 participant