<http://webkit.org/b/66113> [CFNetwork] willCacheResponse() leaks CFCachedURLResponse...
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2011 00:52:28 +0000 (00:52 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2011 00:52:28 +0000 (00:52 +0000)
Reviewed by Joseph Pecoraro.

This first appeared in ToT WebKit r23462 (Windows merge).

* platform/network/cf/ResourceHandleCFNet.cpp:
(WebCore::willCacheResponse): Only retain cachedResponse if we
are returning the same object passed into the method, otherwise
we end up double-retaining the new object created.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp

index 5e00866..44f91fb 100644 (file)
@@ -1,3 +1,16 @@
+2011-08-11  David Kilzer  <ddkilzer@apple.com>
+
+        <http://webkit.org/b/66113> [CFNetwork] willCacheResponse() leaks CFCachedURLResponseRef if delegate changes CacheStoragePolicy
+
+        Reviewed by Joseph Pecoraro.
+
+        This first appeared in ToT WebKit r23462 (Windows merge).
+
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::willCacheResponse): Only retain cachedResponse if we
+        are returning the same object passed into the method, otherwise
+        we end up double-retaining the new object created.
+
 2011-08-05  Nat Duca  <nduca@chromium.org>
 
         [chromium] Make WebViewImpl point at CCLayerTreeHost and related separation
index 7ffd1ca..219f1c4 100644 (file)
@@ -328,13 +328,14 @@ static CFCachedURLResponseRef willCacheResponse(CFURLConnectionRef, CFCachedURLR
     if (handle->client())
         handle->client()->willCacheResponse(handle, policy);
 
-    if (static_cast<CFURLCacheStoragePolicy>(policy) != CFCachedURLResponseGetStoragePolicy(cachedResponse))
+    if (static_cast<CFURLCacheStoragePolicy>(policy) != CFCachedURLResponseGetStoragePolicy(cachedResponse)) {
         cachedResponse = CFCachedURLResponseCreateWithUserInfo(kCFAllocatorDefault, 
                                                                CFCachedURLResponseGetWrappedResponse(cachedResponse),
                                                                CFCachedURLResponseGetReceiverData(cachedResponse),
                                                                CFCachedURLResponseGetUserInfo(cachedResponse), 
                                                                static_cast<CFURLCacheStoragePolicy>(policy));
-    CFRetain(cachedResponse);
+    } else
+        CFRetain(cachedResponse);
 
     return cachedResponse;
 }