Changeset 90705 in webkit


Ignore:
Timestamp:
Jul 10, 2011 7:08:34 PM (13 years ago)
Author:
andersca@apple.com
Message:

WebKit2 is leaking NSCursors created by leakNamedCursor
https://bugs.webkit.org/show_bug.cgi?id=64241
<rdar://problem/9507151>

Reviewed by Oliver Hunt.

../WebCore:

  • platform/mac/CursorMac.mm:

(WebCore::createNamedCursor):
Rename this from leakNamedCursor to createNamedCursor and make it return a
RetainPtr<NSCursor> instead of a raw pointer.

(WebCore::Cursor::ensurePlatformCursor):
Don't leak cursors here. We still won't deallocate cursors during shutdown (which leakNamedCursor
was said to prevent) because the cursor singletons are all allocated from the heap and are never destroyed
anyway.

../WebKit2:

  • Shared/WebCoreArgumentCoders.cpp:

(CoreIPC::::decode):
When decoding a cursor of a known type, make sure to eagerly create the platform cursor
for the cursor singleton. This way we avoid re-creating new NSCursor objects over and over for
standard cursors.

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r90704 r90705  
     12011-07-10  Anders Carlsson  <andersca@apple.com>
     2
     3        WebKit2 is leaking NSCursors created by leakNamedCursor
     4        https://bugs.webkit.org/show_bug.cgi?id=64241
     5        <rdar://problem/9507151>
     6
     7        Reviewed by Oliver Hunt.
     8
     9        * platform/mac/CursorMac.mm:
     10        (WebCore::createNamedCursor):
     11        Rename this from leakNamedCursor to createNamedCursor and make it return a
     12        RetainPtr<NSCursor> instead of a raw pointer.
     13
     14        (WebCore::Cursor::ensurePlatformCursor):
     15        Don't leak cursors here. We still won't deallocate cursors during shutdown (which leakNamedCursor
     16        was said to prevent) because the cursor singletons are all allocated from the heap and are never destroyed
     17        anyway.
     18
    1192011-07-10  Yuta Kitamura  <yutak@chromium.org>
    220
  • trunk/Source/WebCore/platform/mac/CursorMac.mm

    r90088 r90705  
    5454}
    5555
    56 // Leak these cursors intentionally, that way we won't waste time trying to clean them
    57 // up at process exit time.
    58 static NSCursor* leakNamedCursor(const char* name, int x, int y)
     56static RetainPtr<NSCursor> createNamedCursor(const char* name, int x, int y)
    5957{
    6058    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    61     NSString* resourceName = [[NSString alloc] initWithUTF8String:name];
    62     NSImage* cursorImage = [[NSImage alloc] initWithContentsOfFile:
    63         [[NSBundle bundleForClass:[WebCoreCursorBundle class]]
    64         pathForResource:resourceName ofType:@"png"]];
    65     [resourceName release];
    66     NSCursor* cursor = 0;
     59    RetainPtr<NSString> resourceName(AdoptNS, [[NSString alloc] initWithUTF8String:name]);
     60    RetainPtr<NSImage> cursorImage(AdoptNS, [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[WebCoreCursorBundle class]] pathForResource:resourceName.get() ofType:@"png"]]);
     61   
     62    RetainPtr<NSCursor> cursor;
     63
    6764    if (cursorImage) {
    6865        NSPoint hotSpotPoint = {x, y}; // workaround for 4213314
    69         cursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:hotSpotPoint];
    70         [cursorImage release];
     66        cursor.adoptNS([[NSCursor alloc] initWithImage:cursorImage.get() hotSpot:hotSpotPoint]);
    7167    }
    7268    return cursor;
     
    9389        // The pointingHandCursor from NSCursor does not have a shadow on
    9490        // older versions of Mac OS X, so use our own custom cursor.
    95         m_platformCursor = leakNamedCursor("linkCursor", 6, 1);
     91        m_platformCursor = createNamedCursor("linkCursor", 6, 1);
    9692#endif
    9793        break;
     
    10096        break;
    10197    case Cursor::Wait:
    102         m_platformCursor = leakNamedCursor("waitCursor", 7, 7);
     98        m_platformCursor = createNamedCursor("waitCursor", 7, 7);
    10399        break;
    104100    case Cursor::Help:
    105         m_platformCursor = leakNamedCursor("helpCursor", 8, 8);
     101        m_platformCursor = createNamedCursor("helpCursor", 8, 8);
    106102        break;
    107103    case Cursor::Move:
     
    110106        m_platformCursor = wkCursor("Move");
    111107#else
    112         m_platformCursor = leakNamedCursor("moveCursor", 7, 7);
     108        m_platformCursor = createNamedCursor("moveCursor", 7, 7);
    113109#endif
    114110        break;
     
    118114        m_platformCursor = wkCursor("ResizeEast");
    119115#else
    120         m_platformCursor = leakNamedCursor("eastResizeCursor", 14, 7);
     116        m_platformCursor = createNamedCursor("eastResizeCursor", 14, 7);
    121117#endif
    122118        break;
     
    126122        m_platformCursor = wkCursor("ResizeNorth");
    127123#else
    128         m_platformCursor = leakNamedCursor("northResizeCursor", 7, 1);
     124        m_platformCursor = createNamedCursor("northResizeCursor", 7, 1);
    129125#endif
    130126        break;
     
    134130        m_platformCursor = wkCursor("ResizeNortheast");
    135131#else
    136         m_platformCursor = leakNamedCursor("northEastResizeCursor", 14, 1);
     132        m_platformCursor = createNamedCursor("northEastResizeCursor", 14, 1);
    137133#endif
    138134        break;
     
    142138        m_platformCursor = wkCursor("ResizeNorthwest");
    143139#else
    144         m_platformCursor = leakNamedCursor("northWestResizeCursor", 0, 0);
     140        m_platformCursor = createNamedCursor("northWestResizeCursor", 0, 0);
    145141#endif
    146142        break;
     
    150146        m_platformCursor = wkCursor("ResizeSouth");
    151147#else
    152         m_platformCursor = leakNamedCursor("southResizeCursor", 7, 14);
     148        m_platformCursor = createNamedCursor("southResizeCursor", 7, 14);
    153149#endif
    154150        break;
     
    158154        m_platformCursor = wkCursor("ResizeSoutheast");
    159155#else
    160         m_platformCursor = leakNamedCursor("southEastResizeCursor", 14, 14);
     156        m_platformCursor = createNamedCursor("southEastResizeCursor", 14, 14);
    161157#endif
    162158        break;
     
    166162        m_platformCursor = wkCursor("ResizeSouthwest");
    167163#else
    168         m_platformCursor = leakNamedCursor("southWestResizeCursor", 1, 14);
     164        m_platformCursor = createNamedCursor("southWestResizeCursor", 1, 14);
    169165#endif
    170166        break;
     
    173169        m_platformCursor = wkCursor("ResizeWest");
    174170#else
    175         m_platformCursor = leakNamedCursor("westResizeCursor", 1, 7);
     171        m_platformCursor = createNamedCursor("westResizeCursor", 1, 7);
    176172#endif
    177173        break;
     
    180176        m_platformCursor = wkCursor("ResizeNorthSouth");
    181177#else
    182         m_platformCursor = leakNamedCursor("northSouthResizeCursor", 7, 7);
     178        m_platformCursor = createNamedCursor("northSouthResizeCursor", 7, 7);
    183179#endif
    184180        break;
     
    188184        m_platformCursor = wkCursor("ResizeEastWest");
    189185#else
    190         m_platformCursor = leakNamedCursor("eastWestResizeCursor", 7, 7);
     186        m_platformCursor = createNamedCursor("eastWestResizeCursor", 7, 7);
    191187#endif
    192188        break;
     
    195191        m_platformCursor = wkCursor("ResizeNortheastSouthwest");
    196192#else
    197         m_platformCursor = leakNamedCursor("northEastSouthWestResizeCursor", 7, 7);
     193        m_platformCursor = createNamedCursor("northEastSouthWestResizeCursor", 7, 7);
    198194#endif
    199195        break;
     
    202198        m_platformCursor = wkCursor("ResizeNorthwestSoutheast");
    203199#else
    204         m_platformCursor = leakNamedCursor("northWestSouthEastResizeCursor", 7, 7);
     200        m_platformCursor = createNamedCursor("northWestSouthEastResizeCursor", 7, 7);
    205201#endif
    206202        break;
     
    215211        m_platformCursor = [NSCursor IBeamCursorForVerticalLayout];
    216212#else
    217         m_platformCursor = leakNamedCursor("verticalTextCursor", 7, 7);
     213        m_platformCursor = createNamedCursor("verticalTextCursor", 7, 7);
    218214#endif
    219215        break;
    220216    case Cursor::Cell:
    221         m_platformCursor = leakNamedCursor("cellCursor", 7, 7);
     217        m_platformCursor = createNamedCursor("cellCursor", 7, 7);
    222218        break;
    223219    case Cursor::ContextMenu:
     
    225221        m_platformCursor = [NSCursor contextualMenuCursor];
    226222#else
    227         m_platformCursor = leakNamedCursor("contextMenuCursor", 3, 2);
     223        m_platformCursor = createNamedCursor("contextMenuCursor", 3, 2);
    228224#endif
    229225        break;
     
    232228        m_platformCursor = wkCursor("MakeAlias");
    233229#else
    234         m_platformCursor = leakNamedCursor("aliasCursor", 11, 3);
     230        m_platformCursor = createNamedCursor("aliasCursor", 11, 3);
    235231#endif
    236232        break;
     
    239235        m_platformCursor = wkCursor("BusyButClickable");
    240236#else
    241         m_platformCursor = leakNamedCursor("progressCursor", 3, 2);
     237        m_platformCursor = createNamedCursor("progressCursor", 3, 2);
    242238#endif
    243239        break;
    244240    case Cursor::NoDrop:
    245         m_platformCursor = leakNamedCursor("noDropCursor", 3, 1);
     241        m_platformCursor = createNamedCursor("noDropCursor", 3, 1);
    246242        break;
    247243    case Cursor::Copy:
     
    249245        m_platformCursor = [NSCursor dragCopyCursor];
    250246#else
    251         m_platformCursor = leakNamedCursor("copyCursor", 3, 2);
     247        m_platformCursor = createNamedCursor("copyCursor", 3, 2);
    252248#endif
    253249        break;
    254250    case Cursor::None:
    255         m_platformCursor = leakNamedCursor("noneCursor", 7, 7);
     251        m_platformCursor = createNamedCursor("noneCursor", 7, 7);
    256252        break;
    257253    case Cursor::NotAllowed:
     
    259255        m_platformCursor = [NSCursor operationNotAllowedCursor];
    260256#else
    261         m_platformCursor = leakNamedCursor("notAllowedCursor", 11, 11);
     257        m_platformCursor = createNamedCursor("notAllowedCursor", 11, 11);
    262258#endif
    263259        break;
    264260    case Cursor::ZoomIn:
    265         m_platformCursor = leakNamedCursor("zoomInCursor", 7, 7);
     261        m_platformCursor = createNamedCursor("zoomInCursor", 7, 7);
    266262        break;
    267263    case Cursor::ZoomOut:
    268         m_platformCursor = leakNamedCursor("zoomOutCursor", 7, 7);
     264        m_platformCursor = createNamedCursor("zoomOutCursor", 7, 7);
    269265        break;
    270266    case Cursor::Grab:
  • trunk/Source/WebKit2/ChangeLog

    r90694 r90705  
     12011-07-10  Anders Carlsson  <andersca@apple.com>
     2
     3        WebKit2 is leaking NSCursors created by leakNamedCursor
     4        https://bugs.webkit.org/show_bug.cgi?id=64241
     5        <rdar://problem/9507151>
     6
     7        Reviewed by Oliver Hunt.
     8
     9        * Shared/WebCoreArgumentCoders.cpp:
     10        (CoreIPC::::decode):
     11        When decoding a cursor of a known type, make sure to eagerly create the platform cursor
     12        for the cursor singleton. This way we avoid re-creating new NSCursor objects over and over for
     13        standard cursors.
     14
    1152011-07-10  Benjamin Poulain  <benjamin@webkit.org>
    216
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r89161 r90705  
    336336
    337337    if (type != Cursor::Custom) {
    338         cursor = Cursor::fromType(type);
     338        const Cursor& cursorReference = Cursor::fromType(type);
     339        // Calling platformCursor here will eagerly create the platform cursor for the cursor singletons inside WebCore.
     340        // This will avoid having to re-create the platform cursors over and over.
     341        (void)cursorReference.platformCursor();
     342
     343        cursor = cursorReference;
    339344        return true;
    340345    }
Note: See TracChangeset for help on using the changeset viewer.