Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d55eb5d

Browse files
committed
[Windows] Fix GDI resource leaks in the software fallback path
1 parent 46de27a commit d55eb5d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

shell/platform/windows/flutter_window_win32.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void FlutterWindowWin32::OnResetImeComposing() {
243243
bool FlutterWindowWin32::OnBitmapSurfaceUpdated(const void* allocation,
244244
size_t row_bytes,
245245
size_t height) {
246-
HDC dc = ::GetDC(std::get<HWND>(GetRenderTarget()));
246+
HDC dc = ::GetDC(GetWindowHandle());
247247
BITMAPINFO bmi;
248248
memset(&bmi, 0, sizeof(bmi));
249249
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
@@ -255,6 +255,7 @@ bool FlutterWindowWin32::OnBitmapSurfaceUpdated(const void* allocation,
255255
bmi.bmiHeader.biSizeImage = 0;
256256
int ret = SetDIBitsToDevice(dc, 0, 0, row_bytes / 4, height, 0, 0, 0, height,
257257
allocation, &bmi, DIB_RGB_COLORS);
258+
::ReleaseDC(GetWindowHandle(), dc);
258259
return ret != 0;
259260
}
260261

shell/platform/windows/flutter_window_win32_unittests.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ TEST(FlutterWindowWin32Test, CreateDestroy) {
204204
ASSERT_TRUE(TRUE);
205205
}
206206

207+
TEST(FlutterWindowWin32Test, OnBitmapSurfaceUpdated) {
208+
FlutterWindowWin32 win32window(100, 100);
209+
int old_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
210+
211+
constexpr size_t row_bytes = 100 * 4;
212+
constexpr size_t height = 100;
213+
std::array<char, row_bytes * height> allocation;
214+
win32window.OnBitmapSurfaceUpdated(allocation.data(), row_bytes, height);
215+
216+
int new_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
217+
// Check GDI resources leak
218+
EXPECT_EQ(old_handle_count, new_handle_count);
219+
}
220+
207221
// Tests that composing rect updates are transformed from Flutter logical
208222
// coordinates to device coordinates and passed to the text input manager
209223
// when the DPI scale is 100% (96 DPI).

0 commit comments

Comments
 (0)