<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>45198</bug_id>
          
          <creation_ts>2010-09-03 14:12:23 -0700</creation_ts>
          <short_desc>DeleteDC called while non-stock objects still contained.</short_desc>
          <delta_ts>2010-09-07 12:57:56 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brent Fulgham">bfulgham</reporter>
          <assigned_to name="Brent Fulgham">bfulgham</assigned_to>
          <cc>aroben</cc>
    
    <cc>bweinstein</cc>
    
    <cc>commit-queue</cc>
    
    <cc>sfalken</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>274168</commentid>
    <comment_count>0</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2010-09-03 14:12:23 -0700</bug_when>
    <thetext>BoundsChecker identified a resource leak in WebView.cpp (paint), see line 990-1015.

1. A new compatible device context is created to match our target dc. (line 989).
2. We immediately select our backing store into the DC, which replaces whatever compatible bitmap was in the context.
3. We do stuff...
4. We destroy the context.

BoundsChecker claims this is wrong, because the context still contains our non-stock bitmap in it.

Proposed change:

===================================================================
--- WebView.cpp (revision 66733)
+++ WebView.cpp (working copy)
@@ -987,7 +987,7 @@
     m_paintCount++;

     HDC bitmapDC = ::CreateCompatibleDC(hdc);
-    ::SelectObject(bitmapDC, m_backingStoreBitmap-&gt;handle());
+    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap-&gt;handle()
);

     // Update our backing store if needed.
     updateBackingStore(frameView, bitmapDC, backingStoreCompletelyDirty, window
sToPaint);
@@ -1012,6 +1012,7 @@
         updateRootLayerContents();
 #endif

+    ::SelectObject(bitmapDC, oldBitmap);
     ::DeleteDC(bitmapDC);

     if (!dc)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>274182</commentid>
    <comment_count>1</comment_count>
      <attachid>66543</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2010-09-03 14:31:48 -0700</bug_when>
    <thetext>Created attachment 66543
Small patch to clean up some bitmap release operations.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275171</commentid>
    <comment_count>2</comment_count>
      <attachid>66543</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-09-07 11:12:06 -0700</bug_when>
    <thetext>Comment on attachment 66543
Small patch to clean up some bitmap release operations.

I don&apos;t think there are any leaks here. In FullscreenVideoController, the &quot;potentially leaked&quot; bitmap is held in the m_bitmap OwnPtr. In WebView, the &quot;potentially leaked&quot; bitmap is held in the m_backingStoreBitmap RefCountedHBITMAP. In both cases the bitmap is destroyed later.

Is there any other benefit to adding these SelectObject calls?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275177</commentid>
    <comment_count>3</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2010-09-07 11:20:18 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; (From update of attachment 66543 [details])
&gt; I don&apos;t think there are any leaks here. In FullscreenVideoController, the &quot;potentially leaked&quot; bitmap is held in the m_bitmap OwnPtr. In WebView, the &quot;potentially leaked&quot; bitmap is held in the m_backingStoreBitmap RefCountedHBITMAP. In both cases the bitmap is destroyed later.
&gt; 
&gt; Is there any other benefit to adding these SelectObject calls?

I thought the issue was that CreateCompatibleDC creates a DC with a default bitmap object.  When you select in the m_backingStoreBitmap, it replaces the default bitmap object (the handle of which is returned during the SelectObject call.)  If we destroy the DC while it still contains the m_backingStoreBitmap, the original &apos;compatible&apos; bitmap is left dangling.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275180</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-09-07 11:28:14 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; I thought the issue was that CreateCompatibleDC creates a DC with a default bitmap object.  When you select in the m_backingStoreBitmap, it replaces the default bitmap object (the handle of which is returned during the SelectObject call.)  If we destroy the DC while it still contains the m_backingStoreBitmap, the original &apos;compatible&apos; bitmap is left dangling.

CreateCompatibleDC creates a DC with the stock bitmap selected. The description of the stock bitmap from &lt;http://blogs.msdn.com/b/oldnewthing/archive/2010/04/16/9996968.aspx&gt; makes me think we don&apos;t need to bother to select it back in to the DC before destroying the DC, as the stock bitmap is shared across the whole process.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275188</commentid>
    <comment_count>5</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2010-09-07 11:37:26 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; I thought the issue was that CreateCompatibleDC creates a DC with a default bitmap object.  When you select in the m_backingStoreBitmap, it replaces the default bitmap object (the handle of which is returned during the SelectObject call.)  If we destroy the DC while it still contains the m_backingStoreBitmap, the original &apos;compatible&apos; bitmap is left dangling.
&gt; 
&gt; CreateCompatibleDC creates a DC with the stock bitmap selected. The description of the stock bitmap from &lt;http://blogs.msdn.com/b/oldnewthing/archive/2010/04/16/9996968.aspx&gt; makes me think we don&apos;t need to bother to select it back in to the DC before destroying the DC, as the stock bitmap is shared across the whole process.

You feel that an exchange such as the following indicates that we should NOT return the context to its initial state before destroying it?:

&quot;What I am asking is if, *in this specific case*, not restoring the DC before deleting it would introduce a very small leak of some kind or not. And if it causes a leak, what exactly is leaking?

[Since you know it&apos;s not something you&apos;re supposed to be doing in the first place, what does it matter what happens when you do it? Just don&apos;t do it. Here&apos;s what happens: An error occurs. -Raymond]&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275191</commentid>
    <comment_count>6</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-09-07 11:43:50 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; You feel that an exchange such as the following indicates that we should NOT return the context to its initial state before destroying it?:
&gt; 
&gt; &quot;What I am asking is if, *in this specific case*, not restoring the DC before deleting it would introduce a very small leak of some kind or not. And if it causes a leak, what exactly is leaking?
&gt; 
&gt; [Since you know it&apos;s not something you&apos;re supposed to be doing in the first place, what does it matter what happens when you do it? Just don&apos;t do it. Here&apos;s what happens: An error occurs. -Raymond]&quot;

No, that sounds like we should return the context to its initial state. I hadn&apos;t seen those comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275192</commentid>
    <comment_count>7</comment_count>
      <attachid>66543</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-09-07 11:44:10 -0700</bug_when>
    <thetext>Comment on attachment 66543
Small patch to clean up some bitmap release operations.

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275226</commentid>
    <comment_count>8</comment_count>
      <attachid>66543</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2010-09-07 12:57:52 -0700</bug_when>
    <thetext>Comment on attachment 66543
Small patch to clean up some bitmap release operations.

Clearing flags on attachment: 66543

Committed r66902: &lt;http://trac.webkit.org/changeset/66902&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>275228</commentid>
    <comment_count>9</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2010-09-07 12:57:56 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>66543</attachid>
            <date>2010-09-03 14:31:48 -0700</date>
            <delta_ts>2010-09-07 12:57:52 -0700</delta_ts>
            <desc>Small patch to clean up some bitmap release operations.</desc>
            <filename>bitmap_cleanup.patch</filename>
            <type>text/plain</type>
            <size>3063</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYmtpdC93aW4vQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYmtpdC93aW4vQ2hh
bmdlTG9nCShyZXZpc2lvbiA2Njc3MSkKKysrIFdlYmtpdC93aW4vQ2hhbmdlTG9nCSh3b3JraW5n
IGNvcHkpCkBAIC0xLDMgKzEsMTkgQEAKKzIwMTAtMDktMDMgIEJyZW50IEZ1bGdoYW0gIDxiZnVs
Z2hhbUB3ZWJraXQub3JnPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgor
CisgICAgICAgIENsZWFuIHVwIGEgcG90ZW50aWFsIHJlc291cmNlIGxlYWsuCisgICAgICAgIGh0
dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD00NTE5OAorCisgICAgICAgIFNl
dmVyYWwgYml0bWFwIGRldmljZSBjb250ZXh0IHdlcmUgYmVpbmcgY3JlYXRlZCBhbmQgdXNlZCwK
KyAgICAgICAgYW5kIGRlc3Ryb3llZCB3aXRob3V0IHJldHVybmluZyB0aGUgY29udGV4dCB0byBp
dHMgb3JpZ2luYWwKKyAgICAgICAgc3RhdGUuICBUaGlzIHNob3dlZCB1cCBhcyBiaXRtYXAgbGVh
a3MgaW4gQm91bmRzQ2hlY2tlci4KKworICAgICAgICAqIEZ1bGxzY3JlZW5WaWRlb0NvbnRyb2xs
ZXIuY3BwOgorICAgIC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