summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-12 19:43:37 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-12 19:43:37 +0000
commitd69dfccc52ed0404b43b5b04681d189d752776f6 (patch)
tree6b800232b2d7a514633973ed5745aece57083f15 /ui
parentd92a7e670753fa0a24e592acf412d752e0ae6cd8 (diff)
downloadchromium_src-d69dfccc52ed0404b43b5b04681d189d752776f6.zip
chromium_src-d69dfccc52ed0404b43b5b04681d189d752776f6.tar.gz
chromium_src-d69dfccc52ed0404b43b5b04681d189d752776f6.tar.bz2
Fix invalid GDI object destruction sequence.
The bitmap must be unselected before the dc is destroyed. Not sure if this causes gdi leaks. Flagged by BoundsChecker. BUG=109963 TEST=see bug Review URL: http://codereview.chromium.org/9139042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117477 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/icon_util.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/ui/gfx/icon_util.cc b/ui/gfx/icon_util.cc
index bfb5d50..c3055cc 100644
--- a/ui/gfx/icon_util.cc
+++ b/ui/gfx/icon_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -163,14 +163,15 @@ SkBitmap IconUtil::CreateSkBitmapFromHICONHelper(HICON icon,
// obtain the icon's image.
BITMAPV5HEADER h;
InitializeBitmapHeader(&h, s.width(), s.height());
- HDC dc = ::GetDC(NULL);
+ HDC hdc = ::GetDC(NULL);
uint32* bits;
- HBITMAP dib = ::CreateDIBSection(dc, reinterpret_cast<BITMAPINFO*>(&h),
+ HBITMAP dib = ::CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO*>(&h),
DIB_RGB_COLORS, reinterpret_cast<void**>(&bits), NULL, 0);
DCHECK(dib);
- HDC dib_dc = CreateCompatibleDC(dc);
+ HDC dib_dc = CreateCompatibleDC(hdc);
+ ::ReleaseDC(NULL, hdc);
DCHECK(dib_dc);
- ::SelectObject(dib_dc, dib);
+ HGDIOBJ old_obj = ::SelectObject(dib_dc, dib);
// Windows icons are defined using two different masks. The XOR mask, which
// represents the icon image and an AND mask which is a monochrome bitmap
@@ -222,9 +223,9 @@ SkBitmap IconUtil::CreateSkBitmapFromHICONHelper(HICON icon,
}
delete [] opaque;
- ::DeleteDC(dib_dc);
+ ::SelectObject(dib_dc, old_obj);
::DeleteObject(dib);
- ::ReleaseDC(NULL, dc);
+ ::DeleteDC(dib_dc);
return bitmap;
}