Bug 171532

Summary: Leaks always reports "WebKit Malloc Memory Pressure Handler" dispatch_queue/source as leaking
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ggaren, joepeck, msaboff
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix
ggaren: review+
[PATCH] For landing none

Description Joseph Pecoraro 2017-05-01 19:02:46 PDT
Summary:
Leaks bot always reports "WebKit Malloc Memory Pressure Handler" as leaking

This seems like a valid report of a leak, however logically it doesn't appear to be a leak. We should be able to silence the report by saving the source into a member variable or static variable. For example, WebKit::WebMemoryPressureHandler uses a member variable.

Steps to Reproduce:
1. run-webkit-tests --leaks <one-test>
  => Leaks

Leaks:
Leak: 0x7feb425074c0  size=128  zone: DefaultMallocZone_0x10dff3000   OS_dispatch_queue  ObjC  libdispatch.dylib  "WebKit Malloc Memory Pressure Handler" (from JavaScriptCore)
	Call stack: [thread 0x7fffb0c013c0]: 
        | start 
        | main main.mm:66 
        | WTR::TestController::TestController(int, char const**) TestController.cpp:123 
        | WTR::TestController::TestController(int, char const**) TestController.cpp:117 
        | WTR::WebNotificationProvider::WebNotificationProvider() WebNotificationProvider.cpp:65 
        | WTR::WebNotificationProvider::WebNotificationProvider() WebNotificationProvider.cpp:63 
        | WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::HashMap() HashMap.h:76 
        | WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::HashMap() HashMap.h:76 
        | WTF::HashTable<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::KeyValuePairTraits, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> > >::HashTable() HashTable.h:559 
        | WTF::HashTable<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::KeyValuePairTraits, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> > >::HashTable() HashTable.h:553 
        | WTF::Lock::operator new(unsigned long) Lock.h:135 
        | WTF::fastMalloc(unsigned long) FastMalloc.cpp:256 
        | bmalloc::api::malloc(unsigned long) bmalloc.h:43 
        | bmalloc::Cache::allocate(unsigned long) Cache.h:79 
        | bmalloc::Cache::allocateSlowCaseNullCache(unsigned long) Cache.cpp:66 
        | bmalloc::PerThread<bmalloc::Cache>::getSlowCase() PerThread.h:141 
        | bmalloc::Cache::Cache() Cache.cpp:57 
        | bmalloc::Cache::Cache() PerProcess.h:84 
        | bmalloc::PerProcess<bmalloc::Heap>::getSlowCase() PerProcess.h:93 
        | bmalloc::Heap::Heap(std::__1::lock_guard<bmalloc::StaticMutex>&) Heap.cpp:63 
        | bmalloc::Heap::Heap(std::__1::lock_guard<bmalloc::StaticMutex>&) Heap.cpp:56 
        | _dispatch_queue_create_with_target 
        | _os_object_alloc_realized 
        | class_createInstance 
        | calloc 

Leak: 0x7feb42507540  size=176  zone: DefaultMallocZone_0x10dff3000   OS_dispatch_source  ObjC  libdispatch.dylib
	0xb0bd0348 0x00007fff 0x00000001 0x00000000 	H...............
	0x89abcdef 0xffffffff 0x425074c0 0x00007feb 	.........tPB....
	0x00000000 0x00000000 0x00000000 0x00000000 	................
	0x00000000 0x00000000 0x00000000 0x000fffe0 	................
	0x00000044 0x00000000 0xa7c86856 0x00007fff 	D.......Vh......
	0xffffffff 0xffffffff 0x00000000 0x00000000 	................
	0x00000000 0x00000000 0x00000000 0x00000000 	................
	0x00012000 0x00000000 0x00000000 0x0000002c 	. ..........,...
	...
	Call stack: [thread 0x7fffb0c013c0]: 
        | start 
        | main main.mm:66 
        | WTR::TestController::TestController(int, char const**) TestController.cpp:123 
        | WTR::TestController::TestController(int, char const**) TestController.cpp:117 
        | WTR::WebNotificationProvider::WebNotificationProvider() WebNotificationProvider.cpp:65 
        | WTR::WebNotificationProvider::WebNotificationProvider() WebNotificationProvider.cpp:63 
        | WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::HashMap() HashMap.h:76 
        | WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::HashMap() HashMap.h:76 
        | WTF::HashTable<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::KeyValuePairTraits, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> > >::HashTable() HashTable.h:559 
        | WTF::HashTable<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashMap<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*>, WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> >, WTF::PtrHash<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> >, WTF::HashTraits<WTF::HashSet<unsigned long long, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long> > > >::KeyValuePairTraits, WTF::HashTraits<WebKit::WKRetainPtr<OpaqueWKNotificationManager const*> > >::HashTable() HashTable.h:553 
        | WTF::Lock::operator new(unsigned long) Lock.h:135 
        | WTF::fastMalloc(unsigned long) FastMalloc.cpp:256 
        | bmalloc::api::malloc(unsigned long) bmalloc.h:43 
        | bmalloc::Cache::allocate(unsigned long) Cache.h:79 
        | bmalloc::Cache::allocateSlowCaseNullCache(unsigned long) Cache.cpp:66 
        | bmalloc::PerThread<bmalloc::Cache>::getSlowCase() PerThread.h:141 
        | bmalloc::Cache::Cache() Cache.cpp:57 
        | bmalloc::Cache::Cache() PerProcess.h:84 
        | bmalloc::PerProcess<bmalloc::Heap>::getSlowCase() PerProcess.h:93 
        | bmalloc::Heap::Heap(std::__1::lock_guard<bmalloc::StaticMutex>&) Heap.cpp:63 
        | bmalloc::Heap::Heap(std::__1::lock_guard<bmalloc::StaticMutex>&) Heap.cpp:57 
        | dispatch_source_create 
        | _os_object_alloc_realized 
        | class_createInstance 
        | calloc
Comment 1 Geoffrey Garen 2017-05-01 21:30:35 PDT
Yeah we leak it on purpose :(.

I guess we can add a dummy data member for it just to silence the leaks bot.
Comment 2 Joseph Pecoraro 2017-05-05 15:31:15 PDT
Created attachment 309225 [details]
[PATCH] Proposed Fix
Comment 3 Geoffrey Garen 2017-05-05 16:12:32 PDT
Comment on attachment 309225 [details]
[PATCH] Proposed Fix

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

r=me

> Source/bmalloc/bmalloc/Heap.cpp:61
> +    dispatch_resume(m_pressureHandlerDispatchSource);

I guess you should dispatch_release queue here, since we're behaving as if we're not leaking these objects.
Comment 4 Joseph Pecoraro 2017-05-05 16:32:57 PDT
Created attachment 309240 [details]
[PATCH] For landing
Comment 5 WebKit Commit Bot 2017-05-05 17:24:14 PDT
Comment on attachment 309240 [details]
[PATCH] For landing

Clearing flags on attachment: 309240

Committed r216300: <http://trac.webkit.org/changeset/216300>