Title: [92301] branches/safari-534.51-branch/Source

Diff

Modified: branches/safari-534.51-branch/Source/WebCore/ChangeLog (92300 => 92301)


--- branches/safari-534.51-branch/Source/WebCore/ChangeLog	2011-08-03 19:09:34 UTC (rev 92300)
+++ branches/safari-534.51-branch/Source/WebCore/ChangeLog	2011-08-03 19:18:25 UTC (rev 92301)
@@ -1,3 +1,25 @@
+2011-08-03  Lucas Forschler  <lforsch...@apple.com>
+
+    Merged 90705.
+
+    2011-07-10  Anders Carlsson  <ander...@apple.com>
+
+        WebKit2 is leaking NSCursors created by leakNamedCursor
+        https://bugs.webkit.org/show_bug.cgi?id=64241
+        <rdar://problem/9507151>
+
+        Reviewed by Oliver Hunt.
+
+        * 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.
+
 2011-08-02  Lucas Forschler  <lforsch...@apple.com>
 
     Merged 91616.

Modified: branches/safari-534.51-branch/Source/WebCore/platform/mac/CursorMac.mm (92300 => 92301)


--- branches/safari-534.51-branch/Source/WebCore/platform/mac/CursorMac.mm	2011-08-03 19:09:34 UTC (rev 92300)
+++ branches/safari-534.51-branch/Source/WebCore/platform/mac/CursorMac.mm	2011-08-03 19:18:25 UTC (rev 92301)
@@ -53,21 +53,17 @@
     return 0;
 }
 
-// Leak these cursors intentionally, that way we won't waste time trying to clean them
-// up at process exit time.
-static NSCursor* leakNamedCursor(const char* name, int x, int y)
+static RetainPtr<NSCursor> createNamedCursor(const char* name, int x, int y)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    NSString* resourceName = [[NSString alloc] initWithUTF8String:name];
-    NSImage* cursorImage = [[NSImage alloc] initWithContentsOfFile:
-        [[NSBundle bundleForClass:[WebCoreCursorBundle class]]
-        pathForResource:resourceName ofType:@"png"]];
-    [resourceName release];
-    NSCursor* cursor = 0;
+    RetainPtr<NSString> resourceName(AdoptNS, [[NSString alloc] initWithUTF8String:name]);
+    RetainPtr<NSImage> cursorImage(AdoptNS, [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[WebCoreCursorBundle class]] pathForResource:resourceName.get() ofType:@"png"]]);
+    
+    RetainPtr<NSCursor> cursor;
+
     if (cursorImage) {
         NSPoint hotSpotPoint = {x, y}; // workaround for 4213314
-        cursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:hotSpotPoint];
-        [cursorImage release];
+        cursor.adoptNS([[NSCursor alloc] initWithImage:cursorImage.get() hotSpot:hotSpotPoint]);
     }
     return cursor;
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -92,24 +88,24 @@
 #else
         // The pointingHandCursor from NSCursor does not have a shadow on
         // older versions of Mac OS X, so use our own custom cursor.
-        m_platformCursor = leakNamedCursor("linkCursor", 6, 1);
+        m_platformCursor = createNamedCursor("linkCursor", 6, 1);
 #endif
         break;
     case Cursor::IBeam:
         m_platformCursor = [NSCursor IBeamCursor];
         break;
     case Cursor::Wait:
-        m_platformCursor = leakNamedCursor("waitCursor", 7, 7);
+        m_platformCursor = createNamedCursor("waitCursor", 7, 7);
         break;
     case Cursor::Help:
-        m_platformCursor = leakNamedCursor("helpCursor", 8, 8);
+        m_platformCursor = createNamedCursor("helpCursor", 8, 8);
         break;
     case Cursor::Move:
     case Cursor::MiddlePanning:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("Move");
 #else
-        m_platformCursor = leakNamedCursor("moveCursor", 7, 7);
+        m_platformCursor = createNamedCursor("moveCursor", 7, 7);
 #endif
         break;
     case Cursor::EastResize:
@@ -117,7 +113,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeEast");
 #else
-        m_platformCursor = leakNamedCursor("eastResizeCursor", 14, 7);
+        m_platformCursor = createNamedCursor("eastResizeCursor", 14, 7);
 #endif
         break;
     case Cursor::NorthResize:
@@ -125,7 +121,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNorth");
 #else
-        m_platformCursor = leakNamedCursor("northResizeCursor", 7, 1);
+        m_platformCursor = createNamedCursor("northResizeCursor", 7, 1);
 #endif
         break;
     case Cursor::NorthEastResize:
@@ -133,7 +129,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNortheast");
 #else
-        m_platformCursor = leakNamedCursor("northEastResizeCursor", 14, 1);
+        m_platformCursor = createNamedCursor("northEastResizeCursor", 14, 1);
 #endif
         break;
     case Cursor::NorthWestResize:
@@ -141,7 +137,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNorthwest");
 #else
-        m_platformCursor = leakNamedCursor("northWestResizeCursor", 0, 0);
+        m_platformCursor = createNamedCursor("northWestResizeCursor", 0, 0);
 #endif
         break;
     case Cursor::SouthResize:
@@ -149,7 +145,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeSouth");
 #else
-        m_platformCursor = leakNamedCursor("southResizeCursor", 7, 14);
+        m_platformCursor = createNamedCursor("southResizeCursor", 7, 14);
 #endif
         break;
     case Cursor::SouthEastResize:
@@ -157,7 +153,7 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeSoutheast");
 #else
-        m_platformCursor = leakNamedCursor("southEastResizeCursor", 14, 14);
+        m_platformCursor = createNamedCursor("southEastResizeCursor", 14, 14);
 #endif
         break;
     case Cursor::SouthWestResize:
@@ -165,21 +161,21 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeSouthwest");
 #else
-        m_platformCursor = leakNamedCursor("southWestResizeCursor", 1, 14);
+        m_platformCursor = createNamedCursor("southWestResizeCursor", 1, 14);
 #endif
         break;
     case Cursor::WestResize:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeWest");
 #else
-        m_platformCursor = leakNamedCursor("westResizeCursor", 1, 7);
+        m_platformCursor = createNamedCursor("westResizeCursor", 1, 7);
 #endif
         break;
     case Cursor::NorthSouthResize:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNorthSouth");
 #else
-        m_platformCursor = leakNamedCursor("northSouthResizeCursor", 7, 7);
+        m_platformCursor = createNamedCursor("northSouthResizeCursor", 7, 7);
 #endif
         break;
     case Cursor::EastWestResize:
@@ -187,21 +183,21 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeEastWest");
 #else
-        m_platformCursor = leakNamedCursor("eastWestResizeCursor", 7, 7);
+        m_platformCursor = createNamedCursor("eastWestResizeCursor", 7, 7);
 #endif
         break;
     case Cursor::NorthEastSouthWestResize:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNortheastSouthwest");
 #else
-        m_platformCursor = leakNamedCursor("northEastSouthWestResizeCursor", 7, 7);
+        m_platformCursor = createNamedCursor("northEastSouthWestResizeCursor", 7, 7);
 #endif
         break;
     case Cursor::NorthWestSouthEastResize:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("ResizeNorthwestSoutheast");
 #else
-        m_platformCursor = leakNamedCursor("northWestSouthEastResizeCursor", 7, 7);
+        m_platformCursor = createNamedCursor("northWestSouthEastResizeCursor", 7, 7);
 #endif
         break;
     case Cursor::ColumnResize:
@@ -214,54 +210,54 @@
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = [NSCursor IBeamCursorForVerticalLayout];
 #else
-        m_platformCursor = leakNamedCursor("verticalTextCursor", 7, 7);
+        m_platformCursor = createNamedCursor("verticalTextCursor", 7, 7);
 #endif
         break;
     case Cursor::Cell:
-        m_platformCursor = leakNamedCursor("cellCursor", 7, 7);
+        m_platformCursor = createNamedCursor("cellCursor", 7, 7);
         break;
     case Cursor::ContextMenu:
 #if !defined(BUILDING_ON_LEOPARD)
         m_platformCursor = [NSCursor contextualMenuCursor];
 #else
-        m_platformCursor = leakNamedCursor("contextMenuCursor", 3, 2);
+        m_platformCursor = createNamedCursor("contextMenuCursor", 3, 2);
 #endif
         break;
     case Cursor::Alias:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("MakeAlias");
 #else
-        m_platformCursor = leakNamedCursor("aliasCursor", 11, 3);
+        m_platformCursor = createNamedCursor("aliasCursor", 11, 3);
 #endif
         break;
     case Cursor::Progress:
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
         m_platformCursor = wkCursor("BusyButClickable");
 #else
-        m_platformCursor = leakNamedCursor("progressCursor", 3, 2);
+        m_platformCursor = createNamedCursor("progressCursor", 3, 2);
 #endif
         break;
     case Cursor::NoDrop:
-        m_platformCursor = leakNamedCursor("noDropCursor", 3, 1);
+        m_platformCursor = createNamedCursor("noDropCursor", 3, 1);
         break;
     case Cursor::Copy:
 #if !defined(BUILDING_ON_LEOPARD)
         m_platformCursor = [NSCursor dragCopyCursor];
 #else
-        m_platformCursor = leakNamedCursor("copyCursor", 3, 2);
+        m_platformCursor = createNamedCursor("copyCursor", 3, 2);
 #endif
         break;
     case Cursor::None:
-        m_platformCursor = leakNamedCursor("noneCursor", 7, 7);
+        m_platformCursor = createNamedCursor("noneCursor", 7, 7);
         break;
     case Cursor::NotAllowed:
-        m_platformCursor = [NSCursor operationNotAllowedCursor];
+        m_platformCursor = createNamedCursor("notAllowedCursor", 11, 11);
         break;
     case Cursor::ZoomIn:
-        m_platformCursor = leakNamedCursor("zoomInCursor", 7, 7);
+        m_platformCursor = createNamedCursor("zoomInCursor", 7, 7);
         break;
     case Cursor::ZoomOut:
-        m_platformCursor = leakNamedCursor("zoomOutCursor", 7, 7);
+        m_platformCursor = createNamedCursor("zoomOutCursor", 7, 7);
         break;
     case Cursor::Grab:
         m_platformCursor = [NSCursor openHandCursor];

Modified: branches/safari-534.51-branch/Source/WebKit2/ChangeLog (92300 => 92301)


--- branches/safari-534.51-branch/Source/WebKit2/ChangeLog	2011-08-03 19:09:34 UTC (rev 92300)
+++ branches/safari-534.51-branch/Source/WebKit2/ChangeLog	2011-08-03 19:18:25 UTC (rev 92301)
@@ -1,3 +1,21 @@
+2011-08-03  Lucas Forschler  <lforsch...@apple.com>
+
+    Merged 90705.
+
+    2011-07-10  Anders Carlsson  <ander...@apple.com>
+
+        WebKit2 is leaking NSCursors created by leakNamedCursor
+        https://bugs.webkit.org/show_bug.cgi?id=64241
+        <rdar://problem/9507151>
+
+        Reviewed by Oliver Hunt.
+
+        * 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.
+
 2011-08-02  Lucas Forschler  <lforsch...@apple.com>
 
     Merged 91616.

Modified: branches/safari-534.51-branch/Source/WebKit2/Shared/WebCoreArgumentCoders.h (92300 => 92301)


--- branches/safari-534.51-branch/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2011-08-03 19:09:34 UTC (rev 92300)
+++ branches/safari-534.51-branch/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2011-08-03 19:18:25 UTC (rev 92301)
@@ -221,7 +221,12 @@
         WebCore::Cursor::Type type = static_cast<WebCore::Cursor::Type>(typeInt);
 
         if (type != WebCore::Cursor::Custom) {
-            cursor = WebCore::Cursor::fromType(type);
+            const WebCore::Cursor& cursorReference = WebCore::Cursor::fromType(type);
+            // Calling platformCursor here will eagerly create the platform cursor for the cursor singletons inside WebCore.
+            // This will avoid having to re-create the platform cursors over and over.
+            (void)cursorReference.platformCursor();
+
+            cursor = cursorReference;
             return true;
         }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to