microsoft / microsoft/microsoft-ui-xaml
BitmapSource async action lifetime leak
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
BitmapSource::OnStreamReadCompleted transfers a Core reference to the async action into CImageSource::m_pAsyncAction. Normal decode completion reaches CompleteAsyncAction, which fires completion, releases the Core reference, and clears the pointer. During destruction, however, DisconnectImageOperation clears the decode callback; the callback can no longer complete the action, and the legacy destructor leaves m_pAsyncAction alive in Started indefinitely.
See System XAML fix connected to: [task 62354588](http://task.ms/62354588): Fix BitmapSource async action lifetime leak
### Why is this important?
This can and has resulted in memory leaks when CImageSource is destroyed before the decode callback has completed.
### Steps to reproduce the bug
Unit tests reproduces the leak in the System XAML fix PR connected to: [task 62354588](http://task.ms/62354588): Fix BitmapSource async action lifetime leak
### Actual behavior
CImageSource::m_pAsyncAction is leaked when destruction occurs before decode action completion.
### Expected behavior
CImageSource::m_pAsyncAction should not be leaked when destruction occurs before decode action completion.
### Screenshots
_No response_
### NuGet package version
1.8.260317003
### Windows version
Windows 11 (25H2): Build 26200
### Additional context
_No response_
Contributor guide
Research direction
Start with BitmapSource::OnStreamReadCompleted and trace how CImageSource::m_pAsyncAction is handled by CompleteAsyncAction and DisconnectImageOperation. Review the unit-test reproduction from the referenced System XAML fix, then verify that destroying CImageSource before decode completion does not leave the async action in Started or leak its Core reference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100