Skip to content

Fix memory leak on cross thread events - #25783

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_event_leak
Nov 12, 2025
Merged

Fix memory leak on cross thread events#25783
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_event_leak

Conversation

@sbc100

@sbc100 sbc100 commented Nov 12, 2025

Copy link
Copy Markdown
Collaborator

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_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
sbc100 requested review from kripken and tlively November 12, 2025 00:57
@sbc100
sbc100 force-pushed the fix_event_leak branch 2 times, most recently from 66a981b to 40346aa Compare November 12, 2025 20:47
@sbc100
sbc100 enabled auto-merge (squash) November 12, 2025 21:02
@sbc100
sbc100 force-pushed the fix_event_leak branch 2 times, most recently from 516308d to de65277 Compare November 12, 2025 21:57
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
sbc100 disabled auto-merge November 12, 2025 22:56
@sbc100
sbc100 enabled auto-merge (squash) November 12, 2025 22:56
@sbc100
sbc100 merged commit 80269bf into emscripten-core:main Nov 12, 2025
34 checks passed
@sbc100
sbc100 deleted the fix_event_leak branch November 12, 2025 23:48
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.
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.

2 participants