Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Unified Diff: skia/ext/raster_handle_allocator_win.cc

Issue 2629913002: fix leak of hbitmap (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/raster_handle_allocator_win.cc
diff --git a/skia/ext/raster_handle_allocator_win.cc b/skia/ext/raster_handle_allocator_win.cc
index 93e1a252159d01b11b9bafc31041737b20676a0e..013cd50aa0e48846a302aece98266d4fcef41264 100644
--- a/skia/ext/raster_handle_allocator_win.cc
+++ b/skia/ext/raster_handle_allocator_win.cc
@@ -21,9 +21,20 @@ namespace {
static void DeleteHDCCallback(void*, void* context) {
HDC hdc = static_cast<HDC>(context);
- HBITMAP hbitmap = static_cast<HBITMAP>(SelectObject(hdc, nullptr));
- DeleteObject(hbitmap);
- DeleteDC(hdc);
+
+ // We must get this before we call RestoreDC, as that will drop hbitmap and
+ // reselect the original/default bitmap.
+ HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
+ DCHECK(hbitmap);
f(malita) 2017/01/13 15:51:57 nit: DCHECK_NE(hbitmap, nullptr)
reed1 2017/01/13 15:58:08 Done.
+
+ int success = RestoreDC(hdc, -1); // effectly performs the deselect of hbitmap
f(malita) 2017/01/13 15:51:57 nit: bool
reed1 2017/01/13 15:58:08 Done.
+ DCHECK(success);
+
+ // Now we are the only owner, so we can delete our bitmap
+ success = DeleteObject(hbitmap);
+ DCHECK(hbitmap);
f(malita) 2017/01/13 15:51:57 DCHECK_NE
reed1 2017/01/13 15:58:08 Done.
+ success = DeleteDC(hdc);
+ DCHECK(hbitmap);
f(malita) 2017/01/13 15:51:57 DCHECK_NE
reed1 2017/01/13 15:58:08 Done.
}
// Allocate the layer and fill in the fields for the Rec, or return false
@@ -52,6 +63,11 @@ static bool Create(int width,
return false;
}
SetGraphicsMode(hdc, GM_ADVANCED);
+
+ int saveIndex = SaveDC(hdc); // so we can Restore in the delete callback
+ DCHECK(saveIndex != 0);
f(malita) 2017/01/13 15:52:44 DCHECK_NE(saveIndex, 0)
reed1 2017/01/13 15:58:08 Done.
+
+ // Be sure to select *after* we called SaveDC.
SelectObject(hdc, hbitmap);
rec->fReleaseProc = DeleteHDCCallback;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698