#55982: fix: dangling pointer when releasing an OSR shared texture in the paint handler
Description of Change
Recently there have been shared textured dangling-pointer crashes in CI, for example failed job #1 and failed job #2.
OffscreenSharedTextureValue held a non-owning raw_ptr to the heap OffscreenReleaserHolder, and ownership passed to the JS texture's release monitor. Calling texture.release() synchronously from a paint handler freed the holder while the native value was still on the stack in OffScreenVideoConsumer::OnFrameCaptured. When the value was destroyed, the dangling raw_ptr check fired and crashed the browser process with SIGTRAP. This intermittently killed the api-shared-texture spec worker on macOS arm64.
This PR makes the holder ref-counted, and have both the in-flight value and the release monitor hold a scoped_refptr. release() now drops only the JS reference, and the frame goes back to the capturer's pool when the last reference is gone.
This PR also adds a regression test that releases the texture synchronously inside the paint handler. It crashes deterministically without this change.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
Release Notes
Notes: Fixed dangling pointer when releasing a shared texture.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron