[chromium] Fix DC leak in WebScreenInfoFactory.
authorlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jan 2012 23:34:11 +0000 (23:34 +0000)
committerlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jan 2012 23:34:11 +0000 (23:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76203

Reviewed by Dmitry Titov.

Source/JavaScriptCore:

* JavaScriptCore.gyp/JavaScriptCore.gyp: Added OwnGetDCWin.h
* JavaScriptCore.gypi: Added OwnGetDCWin.h
* JavaScriptCore/wtf/win/OwnGetDCWin.h: Made an owner class for GetDC which needs ReleaseDC as opposed to DeleteDC.

Source/WebKit/chromium:

* src/win/WebScreenInfoFactory.cpp:
(WebKit::WebScreenInfoFactory::screenInfo): Use OwnGetDC to ensure its release.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104867 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.gyp/JavaScriptCore.gyp
Source/JavaScriptCore/JavaScriptCore.gypi
Source/JavaScriptCore/wtf/win/OwnGetDCWin.h [new file with mode: 0644]
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/win/WebScreenInfoFactory.cpp

index 301d290..e613cca 100644 (file)
@@ -1,3 +1,14 @@
+2012-01-12  David Levin  <levin@chromium.org>
+
+        [chromium] Fix DC leak in WebScreenInfoFactory.
+        https://bugs.webkit.org/show_bug.cgi?id=76203
+
+        Reviewed by Dmitry Titov.
+
+        * JavaScriptCore.gyp/JavaScriptCore.gyp: Added OwnGetDCWin.h
+        * JavaScriptCore.gypi: Added OwnGetDCWin.h
+        * JavaScriptCore/wtf/win/OwnGetDCWin.h: Made an owner class for GetDC which needs ReleaseDC as opposed to DeleteDC.
+
 2012-01-11  Gavin Barraclough  <barraclough@apple.com>
 
         Allow accessor get/set property to be set to undefined
index bec3ae1..31baeea 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2009 Google Inc. All rights reserved.
+# Copyright (C) 2009, 2012 Google Inc. All rights reserved.
 # 
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
             ['exclude', 'ThreadingPthreads\\.cpp$'],
             ['include', 'Thread(ing|Specific)Win\\.cpp$'],
             ['exclude', 'OSAllocatorPosix\\.cpp$'],
-            ['include', 'OSAllocatorWin\\.cpp$']
+            ['include', 'OSAllocatorWin\\.cpp$'],
+            ['include', 'win/OwnGetDCWin\\.h$'],
           ],
           'include_dirs!': [
             '<(SHARED_INTERMEDIATE_DIR)/webkit',
index c936791..dc47876 100644 (file)
             'wtf/unicode/wince/UnicodeWinCE.cpp',
             'wtf/unicode/wince/UnicodeWinCE.h',
             'wtf/win/MainThreadWin.cpp',
+            'wtf/win/OwnGetDCWin.h',
             'wtf/win/OwnPtrWin.cpp',
             'wtf/wince/FastMallocWinCE.h',
             'wtf/wince/MemoryManager.cpp',
diff --git a/Source/JavaScriptCore/wtf/win/OwnGetDCWin.h b/Source/JavaScriptCore/wtf/win/OwnGetDCWin.h
new file mode 100644 (file)
index 0000000..8944772
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <windows.h>
+
+namespace WTF {
+
+class OwnGetDC {
+public:
+    explicit OwnGetDC(HWND hwnd)
+        : m_hwnd(hwnd)
+        , m_hdc(::GetDC(hwnd))
+    {
+    }
+
+    ~OwnGetDC()
+    {
+        if (m_hdc)
+            ::ReleaseDC(m_hwnd, m_hdc);
+    }
+
+    operator HDC()
+    {
+        return m_hdc;
+    }
+
+private:
+    HWND m_hwnd;
+    HDC m_hdc;
+};
+
+}
+
+using WTF::OwnGetDC;
index 4a0dc97..b6cc848 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-12  David Levin  <levin@chromium.org>
+
+        [chromium] Fix DC leak in WebScreenInfoFactory.
+        https://bugs.webkit.org/show_bug.cgi?id=76203
+
+        Reviewed by Dmitry Titov.
+
+        * src/win/WebScreenInfoFactory.cpp:
+        (WebKit::WebScreenInfoFactory::screenInfo): Use OwnGetDC to ensure its release.
+
 2012-01-12  Dana Jansens  <danakj@chromium.org>
 
         [skia] Track a simple opaque area when painting via PlatformContextSkia and save in LayerTextureUpdater
index 9263dea..e6afb5c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -33,6 +33,8 @@
 
 #include "WebScreenInfo.h"
 
+#include <wtf/win/OwnGetDCWin.h>
+
 #include <windows.h>
 
 namespace WebKit {
@@ -60,7 +62,8 @@ WebScreenInfo WebScreenInfoFactory::screenInfo(HWND window)
     devMode.dmDriverExtra = 0;
     EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
 
-    HDC hdc = GetDC(0);
+    OwnGetDC hdc(0);
+    ASSERT(hdc);
 
     WebScreenInfo results;
     results.horizontalDPI = GetDeviceCaps(hdc, LOGPIXELSX);