Fix memory leak on cross thread events - #25783
Merged
Merged
Conversation
tlively
approved these changes
Nov 12, 2025
sbc100
force-pushed
the
fix_event_leak
branch
2 times, most recently
from
November 12, 2025 20:47
66a981b to
40346aa
Compare
sbc100
enabled auto-merge (squash)
November 12, 2025 21:02
sbc100
force-pushed
the
fix_event_leak
branch
2 times, most recently
from
November 12, 2025 21:57
516308d to
de65277
Compare
I believe that we started leaking the event data for cross-thread html5 events in emscripten-core#20370. Prior to that change we use `_emscripten_dispatch_to_thread` which took care of free'ing the event data once it was consumed on the target thread. After this change we copy make copy of the event strut in `_emscripten_run_callback_on_thread` and then free it once the callback is run. This change also avoid an extra malloc per event.
sbc100
force-pushed
the
fix_event_leak
branch
from
November 12, 2025 22:47
de65277 to
3b5ca18
Compare
sbc100
disabled auto-merge
November 12, 2025 22:56
sbc100
enabled auto-merge (squash)
November 12, 2025 22:56
inolen
pushed a commit
to inolen/emscripten
that referenced
this pull request
Feb 13, 2026
I believe that we started leaking the event data for cross-thread html5 events in emscripten-core#20370. Prior to that change we use `_emscripten_dispatch_to_thread` which took care of free'ing the event data once it was consumed on the target thread. After this change we copy make copy of the event strut in `_emscripten_run_callback_on_thread` and then free it once the callback is run. This change also avoids an extra malloc per event, and cleans up libhtml5.js a little.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Jul 7, 2026
In emscripten-core#25783 (80269bf), _emscripten_run_callback_on_thread was updated to take an event_data_size parameter. However, call sites passing 0 for event data in libhtml5.js and libhtml5_webgl.js were missed and left with 5 arguments instead of 6, causing userData to be passed as event_data_size and user_data to be omitted.
sbc100
added a commit
that referenced
this pull request
Jul 7, 2026
…27264) In #25783, `_emscripten_run_callback_on_thread` was updated to take an event_data_size parameter. However, call sites passing 0 for event data in `libhtml5.js` and `libhtml5_webgl.js` were missed and left with 5 arguments instead of 6, causing `userData` to be passed as `event_data_size` and `user_data` to be omitted.
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.
I believe that we started leaking the event data for cross-thread html5 events in #20370.
Prior to that change we use
_emscripten_dispatch_to_threadwhich took care of free'ing the event data once it was consumed on the target thread.After this change we copy make copy of the event strut in
_emscripten_run_callback_on_threadand then free it once the callback is run.This change also avoids an extra malloc per event, and cleans up libhtml5.js a little.