Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix wrong deallocation management for JSClosure with FinalizationRegistry#393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kateinoigakukun merged 4 commits intomainfromyt/jsclosure-fix
Aug 4, 2025

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukunkateinoigakukun commentedAug 3, 2025
edited
Loading

In FinalizationRegistry mode, theswjs_free_host_function should be called with the Swift heap object ID, not the JS closure object ID.
The wrong argument was causing:

  • Swift closures to be leaked, because FinalizationRegistry attempted to release a JS object ID that was never registered as a Swift closure.
  • Unintended deallocation of unrelated closures when a reused JS object ID happened to match a valid Swift closure ID by coincidence after so many JSObject allocations (likely 10~30 million allocations). This eventually led to crashes withThe JSClosure has been already released by Swift side.

Stop managing JSOneshotClosure by FinalizationRegistry

JSOneshotClosure manages its lifetime by itself, so it doesn't require
nondeterministic FinalizationRegistry. Additionally, use of FinalizationRegistry
was unsafe for the case:

  1. JSOneshotClosure C1 is created
  2. C1 is called, and destroyed
  3. JSOneshotClosure C2 is created at the same address of C1
  4. C1's finalizer callback is called

…stryIn FinalizationRegistry mode, the `swjs_free_host_function` shouldbe called with the Swift heap object ID, not the JS closure object ID.The wrong argument was causing:- Swift closures to be leaked, because FinalizationRegistry attempted  to release a JS object ID that was never registered as a Swift closure.- Unintended deallocation of unrelated closures when a reused JS object ID  happened to match a valid Swift closure ID by coincidence. This  eventually led to crashes with `The JSClosure has been already released by Swift side.`
JSOneshotClosure manages its lifetime by itself, so it doesn't requirenondeterministic FinalizationRegistry. Additionally, use of FinalizationRegistrywas unsafe for the case:1. JSOneshotClosure C1 is created2. C1 is called, and destroyed3. JSOneshotClosure C2 is created at the same address of C14. C1's finalizer callback is called
@kateinoigakukunkateinoigakukun merged commit4504e13 intomainAug 4, 2025
8 checks passed
@kateinoigakukunkateinoigakukun deleted the yt/jsclosure-fix branchAugust 4, 2025 02:46
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@lowkahonnlowkahonnlowkahonn approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@kateinoigakukun@lowkahonn

[8]ページ先頭

©2009-2025 Movatter.jp