Files
itu-itis24-iyigun24andClaude Opus 5 9521e6cdf9 Fix use-after-free when unregistering script classes twice (#27143)
ScBase::Unregister() freed the class prototype but kept proto and
protoCtx. The script classes are globals and the JS runtime is freed
when a context is destroyed, so these values become dangling pointers.

The script classes are registered only by ScriptEngine::Initialise(),
but ~ScriptEngine() always unregisters them. Destroying a context whose
script engine was never initialised, after an initialised one had been
destroyed, therefore freed the stale prototype again through the freed
JSContext. On Windows this crashed WaterObjectTest when it ran after
TileElementsViewTests in the same test process.

Reset proto and protoCtx after freeing them, and add a test that
destroys an uninitialised context after an initialised one.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-26 11:00:41 +11:00
..