Bug 146501

Summary: [Mac] Numerous CGColor leaks in swipe gestures
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: WebKit2Assignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, darin, joepeck, simon.fraser, thorton
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix none

Description Joseph Pecoraro 2015-07-01 00:40:49 PDT
* SUMMARY
[Mac] Numerous CGColor leaks in swipe gestures

Unsure of the exact steps to reproduce.

* LEAK
Leak: 0x7ffee400cfb0  size=80  zone: DefaultMallocZone_0x10ab96000   CGColor  CFType  CoreGraphics
	Call stack: [thread 0x10aa86000]: 
        | 0x1 
        | start 
        | NSApplicationMain 
        | -[NSApplication run] 
        | -[BrowserApplication sendEvent:] 
        | -[NSApplication sendEvent:] 
        | -[BrowserWindow sendEvent:] 
        | -[Window sendEvent:] 
        | -[NSWindow sendEvent:] 
        | -[NSWindow _reallySendEvent:isDelayedEvent:] 
        | -[BrowserWKView scrollWheel:] 
        | -[WKView scrollWheel:] 
        | WebKit::ViewGestureController::handleScrollWheelEvent(NSEvent*) 
        | WebKit::ViewGestureController::trackSwipeGesture(NSEvent*, WebKit::ViewGestureController::SwipeDirection) 
        | -[NSEvent trackSwipeEventWithOptions:dampenAmountThresholdMin:max:usingHandler:] 
        | -[NSEvent _trackSwipeEventWithOptions:dampenAmountThresholdMin:max:trackingDistance:axis:velocityFilterClass:usingHandler:] 
        | ___trackSwipeWithScrollEvent_block_invoke 
        | ___ZN6WebKit21ViewGestureController17trackSwipeGestureEP7NSEventNS0_14SwipeDirectionE_block_invoke 
        | WebKit::ViewGestureController::beginSwipeGesture(WebKit::WebBackForwardListItem*, WebKit::ViewGestureController::SwipeDirection) 
        | CGColorCreateGenericGray 
        | create_color 
        | CGTypeCreateInstance 
        | _CFRuntimeCreateInstance 
        | malloc_zone_malloc 

* NOTES
- ViewGestureController::beginSwipeGesture certainly looks like it leaks:

        [m_swipeShadowLayer setColors:@[
            (id)CGColorCreateGenericGray(0, 1.),
            (id)CGColorCreateGenericGray(0, 0.99),
            (id)CGColorCreateGenericGray(0, 0.98),
            (id)CGColorCreateGenericGray(0, 0.95),
            ...
        ]];
Comment 1 Joseph Pecoraro 2015-07-01 00:41:03 PDT
What is the elegant way to do this without leaking? Is it this?

  (id)adoptCF(CGColorCreateGenericGray(...)).get()
Comment 2 Joseph Pecoraro 2015-07-01 00:56:51 PDT
Created attachment 255908 [details]
[PATCH] Proposed Fix

Seems to work!
Comment 3 Tim Horton 2015-07-01 01:06:53 PDT
Comment on attachment 255908 [details]
[PATCH] Proposed Fix

Woah, good catch. Thankfully never shipped.
Comment 4 WebKit Commit Bot 2015-07-01 01:55:59 PDT
Comment on attachment 255908 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 255908

Committed r186174: <http://trac.webkit.org/changeset/186174>
Comment 5 WebKit Commit Bot 2015-07-01 01:56:03 PDT
All reviewed patches have been landed.  Closing bug.
Comment 6 Darin Adler 2015-07-01 09:39:32 PDT
Comment on attachment 255908 [details]
[PATCH] Proposed Fix

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

> Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm:640
> +            (id)adoptCF(CGColorCreateGenericGray(0, 1.)).get(),

Cries out for a helper function.