Repository navigation
own: <any>undefined / <any>null in an object literal field is moved in, not freed twice - #978
Merged
Merged
Conversation
… 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>
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.
Fixes the -mm=own double free recorded in TSLANG 153: an object literal field holding
<any>undefinedor<any>null, such as{ t: <any>undefined, n: 1 }, was freed twice.Cause.
own_facts::isConstantDatalooks through casts fornull/undefinedand treats what it finds as data that holds no heap block. That is right fornullwidened toC | null. It is wrong for a value boxed intoany, because the box is a new heap block. As a result,checkValueMovesreturned 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
anyorunknownnow counts as a heap block of its own. With<any>5the box was already handled as a move, so this brings<any>undefinedand<any>nullin line with it.Before this, #975 worked around the bug for generators by starting
.thrownwith<any>0. That workaround stays in place; it is harmless.Tests. New test
00any_undefined_field.ts(compile, JIT, rc, own). Verified locally:🤖 Generated with Claude Code