Centralize exception ownership and fix exception unwinding to prevent leaks#551
Open
nbeerbower wants to merge 2 commits into
Open
Centralize exception ownership and fix exception unwinding to prevent leaks#551nbeerbower wants to merge 2 commits into
nbeerbower wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ctx->exception_state.*andvalue_retain/VALUE_RELEASEmanually, causing inconsistent ownership and potential leaks when an active exception is superseded during unwinding (defer/finally) or when contexts are reused.Description
exception_set_value(ExecutionContext*, Value)andexception_clear(ExecutionContext*)to manage exception-state ownership and release any replaced value. (Added tointernal.hand implemented inruntime/context.c.)exception_set_value/exception_clear, and updateruntimehelpers (runtime_error*) to use the centralized APIs instead of manual retain patterns.deferandfinallyrestore or release saved exceptions correctly (saved exceptions are released when a defer/finally overrides them) by saving/restoring or releasingsaved_exceptionindefer_stack_executeandtry/finallylogic inruntime/statements.c.throwtransfer ownership through the new helper and protect against double-ownership during nested throws.exception_clearso aWasmContextbecomes reusable after a runtime error.tests/memory/exception_override_cleanup.hmlthat verifies exception values are released when overridden bydefer/finally, and wire it intotests/memory/regression/run_leak_tests.sh.src/backends/interpreter/runtime/context.c,src/backends/interpreter/runtime/statements.c,src/backends/interpreter/internal.h,src/backends/interpreter/ffi.c,src/backends/interpreter/environment.c, and many builtin/io/wasm sources). See diff for full list.Testing
make asan -j2(ASAN build completed successfully). — succeeded../tests/memory/regression/run_leak_tests.sh(quick and full runs): all regression tests passed, including newexception_override_cleanup.hml. — succeeded (no leaks detected).make clean && make -j2) and non-ASAN builds to validate integration; initial ASAN linking hiccup observed during incremental build but resolved by clean rebuild. — final full build succeeded.Codex Task