<?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>155515</bug_id>
          
          <creation_ts>2016-03-15 15:14:38 -0700</creation_ts>
          <short_desc>[Win] Correct double-release of CFURLConnectionRef</short_desc>
          <delta_ts>2016-03-15 17:00:10 -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>WebKit Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=155522</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</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>bfulgham</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1175136</commentid>
    <comment_count>0</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 15:14:38 -0700</bug_when>
    <thetext>A double-release of a CFURLConnectionRef was identified in one of the WebDownload::init methods:

    CFURLConnectionRef connection = handle-&gt;connection();

    …

    m_download = adoptCF(CFURLDownloadCreateAndStartWithLoadingConnection(0, connection, request.cfURLRequest(UpdateHTTPBody), response.cfURLResponse(), &amp;client));

    …

    // The CFURLDownload either starts successfully and retains the CFURLConnection, 
    // or it fails to creating and we have a now-useless connection with a dangling ref. 
    // Either way, we need to release the connection to balance out ref counts
    handle-&gt;releaseConnectionForDownload();
    CFRelease(connection);

The last line, the call to CFRelease(connection), is wrong and should be removed, because ResourceHandle::connection() just does 

    d-&gt;m_connection.get()

CFURLDownloadCreateAndStartWithLoadingConnection() can retain the connection per the comment, while ResourceHandle:: releaseConnectionForDownload() lets go of the connection.

But then we release the connection via the raw pointer we stole from the ResourceHandle, as if we thought ResourceHandle::connection() returned a retained connection!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175137</commentid>
    <comment_count>1</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 15:15:30 -0700</bug_when>
    <thetext>&lt;rdar://problem/25159143&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175143</commentid>
    <comment_count>2</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 15:19:33 -0700</bug_when>
    <thetext>Note: It looks like this code is not tested in the LayoutTest system because the &apos;http/tests/downloads/&apos; test suite is skipped on Windows due to missing DRT features.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175144</commentid>
    <comment_count>3</comment_count>
      <attachid>274141</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 15:21:34 -0700</bug_when>
    <thetext>Created attachment 274141
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175149</commentid>
    <comment_count>4</comment_count>
      <attachid>274143</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 15:25:24 -0700</bug_when>
    <thetext>Created attachment 274143
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175175</commentid>
    <comment_count>5</comment_count>
      <attachid>274150</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 16:05:02 -0700</bug_when>
    <thetext>Created attachment 274150
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175200</commentid>
    <comment_count>6</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 16:59:50 -0700</bug_when>
    <thetext>Testing infrastructure on Windows is needed to avoid breaking this in the future. See Bug 155522.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1175201</commentid>
    <comment_count>7</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2016-03-15 17:00:10 -0700</bug_when>
    <thetext>Committed r198244: &lt;http://trac.webkit.org/changeset/198244&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>274141</attachid>
            <date>2016-03-15 15:21:34 -0700</date>
            <delta_ts>2016-03-15 15:24:53 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-155515-20160315154439.patch</filename>
            <type>text/plain</type>
            <size>217</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJLaXQvd2luL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09CkluZGV4OiBTb3Vy
Y2UvV2ViS2l0L3dpbi9XZWJEb3dubG9hZENGTmV0LmNwcAo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Cg==
</data>

          </attachment>
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>274143</attachid>
            <date>2016-03-15 15:25:24 -0700</date>
            <delta_ts>2016-03-15 16:04:59 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>double_release.patch</filename>
            <type>text/plain</type>
            <size>1116</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IENoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT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IHdheSwgd2UgbmVl
ZCB0byByZWxlYXNlIHRoZSBjb25uZWN0aW9uIHRvIGJhbGFuY2Ugb3V0IHJlZiBjb3VudHMKICAg
ICBoYW5kbGUtPnJlbGVhc2VDb25uZWN0aW9uRm9yRG93bmxvYWQoKTsKLSAgICBDRlJlbGVhc2Uo
Y29ubmVjdGlvbik7CiB9CiAKIHZvaWQgV2ViRG93bmxvYWQ6OmluaXQoY29uc3QgVVJMJiB1cmws
IElXZWJEb3dubG9hZERlbGVnYXRlKiBkZWxlZ2F0ZSkK
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>274150</attachid>
            <date>2016-03-15 16:05:02 -0700</date>
            <delta_ts>2016-03-15 16:59:04 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-155515-20160315160451.patch</filename>
            <type>text/plain</type>
            <size>1265</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJLaXQvd2luL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2Uv
V2ViS2l0L3dpbi9DaGFuZ2VMb2cJKHJldmlzaW9uIDE5ODIxNikKKysrIFNvdXJjZS9XZWJLaXQv
d2luL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE1IEBACisyMDE2LTAzLTE1
ICBCcmVudCBGdWxnaGFtICA8YmZ1bGdoYW1AYXBwbGUuY29tPgorCisgICAgICAgIFtXaW5dIENv
cnJlY3QgZG91YmxlLXJlbGVhc2Ugb2YgQ0ZVUkxDb25uZWN0aW9uUmVmCisgICAgICAgIGh0dHBz
Oi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xNTU1MTUKKyAgICAgICAgPHJkYXI6
Ly9wcm9ibGVtLzI1MTU5MTQzPgorCis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Rvd25sb2FkRGVsZWdhdGUq
IGRlbGVnYXRlKQo=
</data>
<flag name="review"
          id="298656"
          type_id="1"
          status="+"
          setter="thorton"
    />
          </attachment>
      

    </bug>

</bugzilla>