Skip to content

Conversation

@mahmuttaskiran
Copy link

@mahmuttaskiran mahmuttaskiran commented Dec 25, 2025

This PR adds a virtual destructor to the Codec class. (base class for MultiFrameCodec and SingleFrameCodec).

The Codec class is referenced via fml::RefPtr<Codec> however doesn't declare destructor.

Hoping to fix #161031


I was unable to reproduce that specific crash (affecting thousands of users every month in our app) locally as it appears to be subtle memory corruption or race condition. So, I am opening this PR hoping that it fixes the reported crash by ensuring proper cleanup of resources. I would appreciate review and support from engine engineers to validate the fix.

Pre-launch Checklist

talabat.com Talabat Flutter PRs

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added the engine flutter/engine related. See also e: labels. label Dec 25, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a virtual destructor to the Codec base class. This is a correct and necessary change for a polymorphic base class with virtual functions, as it ensures proper destruction of derived class objects (like MultiFrameCodec and SingleFrameCodec) when deleted through a base class pointer. This change prevents undefined behavior and potential memory leaks, addressing the issue described in the pull request. The fix aligns with C++ best practices and the Google C++ Style Guide.

@mahmuttaskiran
Copy link
Author

I might be mistaken here. I now see that RefCountedThreadSafe defines Release method which casts T to most derived type, in this case SingleFrameCodec and MultiFrameCodec classes which already defines destructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[engine] potential crash on deref of canvas_image_ in single_frame_codec.cc.

1 participant