Skip to content

own: <any>undefined / <any>null in an object literal field is moved in, not freed twice - #978

Merged
ASDAlexander77 merged 1 commit into
mainfrom
own-any-undefined-field
Nov 21, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
own-any-undefined-field

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes the -mm=own double free recorded in TSLANG 153: an object literal field holding <any>undefined or <any>null, such as { t: <any>undefined, n: 1 }, was freed twice.

Cause. own_facts::isConstantData looks through casts for null/undefined and treats what it finds as data that holds no heap block. That is right for null widened to C | null. It is wrong for a value boxed into any, because the box is a new heap block. As a result, checkValueMoves returned early and never checked the store of the box into the object as a move. The object took the box, and the temporary's own release freed it as well. wasm's checked heap reported it ("free of ...: not a block the heap gave out"), and so did Linux under own. Windows didn't notice.

Fix. A cast into any or unknown now counts as a heap block of its own. With <any>5 the box was already handled as a move, so this brings <any>undefined and <any>null in line with it.

Before this, #975 worked around the bug for generators by starting .thrown with <any>0. That workaround stays in place; it is harmless.

Tests. New test 00any_undefined_field.ts (compile, JIT, rc, own). Verified locally:

  • ctest: 8785 tests, 0 failed;
  • wasm32 own tester suite, debug: 618 passed, 0 failed;
  • the repros under wasm own and rc, and natively in gc, rc and own.

🤖 Generated with Claude Code

… in, not released twice

own_facts::isConstantData took null or undefined seen through its casts for data nothing owns - a box into
`any` included - so checkValueMoves returned before checking the store of `{ t: <any>undefined }`'s box into
the object as a move: the store took the box and the temporary's release gave it back too, a double free that
wasm's checked heap and Linux caught (Windows did not). A cast into `any` or `unknown` makes a block of its own.
Test 00any_undefined_field.ts (compile, JIT, rc, own); TSLANG 153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit e40c66e into main Nov 21, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the own-any-undefined-field branch November 21, 2026 18:12
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.

1 participant