Bug 118533 - WebResourceCacheManager::cfURLCacheHostNamesWithCallback leaks an array (pointed out by the clang static analyzer)
Summary: WebResourceCacheManager::cfURLCacheHostNamesWithCallback leaks an array (poin...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jessie Berlin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-10 09:56 PDT by Jessie Berlin
Modified: 2013-07-11 15:28 PDT (History)
4 users (show)

See Also:


Attachments
Patch (1.86 KB, patch)
2013-07-10 10:03 PDT, Jessie Berlin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jessie Berlin 2013-07-10 09:56:57 PDT
#if ENABLE(CACHE_PARTITIONING)
void WebResourceCacheManager::cfURLCacheHostNamesWithCallback(CacheCallback callback)
{
    WKCFURLCacheCopyAllPartitionNames(^(CFArrayRef partitionNames) {
        CFMutableArrayRef hostNames = CFArrayCreateMutableCopy(0, 0, WKCFURLCacheCopyAllHostNamesInPersistentStoreForPartition(CFSTR("")));
        CFArrayAppendArray(hostNames, partitionNames, CFRangeMake(0, CFArrayGetCount(partitionNames)));
        CFRelease(partitionNames);
        callback(adoptCF(hostNames));
    });
}
#endif

The array returned by the call to WKCFURLCacheCopyAllHostNamesInPersistentStoreForPartition(CFSTR("”)) is getting leaked.
Comment 1 Jessie Berlin 2013-07-10 10:03:25 PDT
Created attachment 206395 [details]
Patch
Comment 2 Anders Carlsson 2013-07-10 13:02:55 PDT
Comment on attachment 206395 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=206395&action=review

> Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:68
> +        CFMutableArrayRef hostNames = CFArrayCreateMutableCopy(0, 0, hostNamesInPersistentStore.get());

I think you can use a RetainPtr here (with adoptCF).

> Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:71
>          callback(adoptCF(hostNames));

and then just call std::move(hostNames) here.
Comment 3 Jessie Berlin 2013-07-11 09:21:51 PDT
(In reply to comment #2)
> (From update of attachment 206395 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=206395&action=review
> 
> > Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:68
> > +        CFMutableArrayRef hostNames = CFArrayCreateMutableCopy(0, 0, hostNamesInPersistentStore.get());
> 
> I think you can use a RetainPtr here (with adoptCF).

Done.

> 
> > Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:71
> >          callback(adoptCF(hostNames));
> 
> and then just call std::move(hostNames) here.

Done.

Thanks for the review!
Comment 4 Jessie Berlin 2013-07-11 15:28:34 PDT
Comment on attachment 206395 [details]
Patch

Committed in http://trac.webkit.org/changeset/152578