Skip to content

[engine] dont double free surface texture interop objects. #170284

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2025

Conversation

jonahwilliams
Copy link
Member

Fixes #152459

I suspect the double free is related to #162147 .

With the Impeller backend, the second free is performed by the reactor and comes only after the application has returned to the foreground. This increaases the likelyhood that we nuke a handle that is in active use by another part of the system.

Since SurfaceTexture:: detachFromGLContext is documented as releasing the texture, we don't need to free it at all and can "leak" it on our side.

@github-actions github-actions bot added platform-android Android applications specifically engine flutter/engine repository. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jun 9, 2025
@@ -55,6 +55,7 @@ void SurfaceTextureExternalTextureGLImpeller::ProcessFrame(

void SurfaceTextureExternalTextureGLImpeller::Detach() {
SurfaceTextureExternalTexture::Detach();
texture_->Leak();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave a comment mentioning the docstring saying that the detach will collect the handle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -229,6 +230,10 @@ TextureGLES::~TextureGLES() {
}
}

void TextureGLES::Leak() {
handle_ = HandleGLES::DeadHandle();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ReactorGLES::CollectHandle handle a DeadHandle? We should just add an early return in that case since we'll be acquiring locks and such.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2025
Copy link
Contributor

auto-submit bot commented Jun 9, 2025

autosubmit label was removed for flutter/flutter/170284, because - The status or check suite Linux docs_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2025
@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 9, 2025
Copy link
Contributor

auto-submit bot commented Jun 9, 2025

autosubmit label was removed for flutter/flutter/170284, because - The status or check suite Linux build_android_host_app_with_module_aar has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 10, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 10, 2025
Merged via the queue into flutter:master with commit 2d30ce5 Jun 10, 2025
184 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e: impeller Impeller rendering backend issues and features requests engine flutter/engine repository. See also e: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential double-free of OpenGL texture in SurfaceTexture interop.
2 participants