WebCore::fillWithEmptyClients adopts new empty clients before leaking their pointers
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Oct 2013 20:16:49 +0000 (20:16 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Oct 2013 20:16:49 +0000 (20:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122945

Reviewed by Anders Carlsson.

* loader/EmptyClients.cpp:
(WebCore::fillWithEmptyClients): Store the static empty clients as NeverDestroyed, rather than
adopting the pointer of each heap-allocated object and then immediately leaking that pointer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157807 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.cpp

index 641e2f2..59a4f11 100644 (file)
@@ -1,5 +1,16 @@
 2013-10-22  Zan Dobersek  <zdobersek@igalia.com>
 
+        WebCore::fillWithEmptyClients adopts new empty clients before leaking their pointers
+        https://bugs.webkit.org/show_bug.cgi?id=122945
+
+        Reviewed by Anders Carlsson.
+
+        * loader/EmptyClients.cpp:
+        (WebCore::fillWithEmptyClients): Store the static empty clients as NeverDestroyed, rather than
+        adopting the pointer of each heap-allocated object and then immediately leaking that pointer.
+
+2013-10-22  Zan Dobersek  <zdobersek@igalia.com>
+
         Simplify HRTFDatabaseLoader's load map
         https://bugs.webkit.org/show_bug.cgi?id=122944
 
index 370272c..fc24acb 100644 (file)
@@ -35,6 +35,7 @@
 #include "Frame.h"
 #include "FrameNetworkingContext.h"
 #include "HTMLFormElement.h"
+#include <wtf/NeverDestroyed.h>
 
 #if ENABLE(INPUT_TYPE_COLOR)
 #include "ColorChooser.h"
@@ -44,27 +45,27 @@ namespace WebCore {
 
 void fillWithEmptyClients(Page::PageClients& pageClients)
 {
-    static ChromeClient* dummyChromeClient = adoptPtr(new EmptyChromeClient).leakPtr();
-    pageClients.chromeClient = dummyChromeClient;
+    static NeverDestroyed<EmptyChromeClient> dummyChromeClient;
+    pageClients.chromeClient = &dummyChromeClient.get();
 
 #if ENABLE(CONTEXT_MENUS)
-    static ContextMenuClient* dummyContextMenuClient = adoptPtr(new EmptyContextMenuClient).leakPtr();
-    pageClients.contextMenuClient = dummyContextMenuClient;
+    static NeverDestroyed<EmptyContextMenuClient> dummyContextMenuClient;
+    pageClients.contextMenuClient = &dummyContextMenuClient.get();
 #endif
 
 #if ENABLE(DRAG_SUPPORT)
-    static DragClient* dummyDragClient = adoptPtr(new EmptyDragClient).leakPtr();
-    pageClients.dragClient = dummyDragClient;
+    static NeverDestroyed<EmptyDragClient> dummyDragClient;
+    pageClients.dragClient = &dummyDragClient.get();
 #endif
 
-    static EditorClient* dummyEditorClient = adoptPtr(new EmptyEditorClient).leakPtr();
-    pageClients.editorClient = dummyEditorClient;
+    static NeverDestroyed<EmptyEditorClient> dummyEditorClient;
+    pageClients.editorClient = &dummyEditorClient.get();
 
-    static InspectorClient* dummyInspectorClient = adoptPtr(new EmptyInspectorClient).leakPtr();
-    pageClients.inspectorClient = dummyInspectorClient;
+    static NeverDestroyed<EmptyInspectorClient> dummyInspectorClient;
+    pageClients.inspectorClient = &dummyInspectorClient.get();
 
-    static FrameLoaderClient* dummyFrameLoaderClient = new EmptyFrameLoaderClient;
-    pageClients.loaderClientForMainFrame = dummyFrameLoaderClient;
+    static NeverDestroyed<EmptyFrameLoaderClient> dummyFrameLoaderClient;
+    pageClients.loaderClientForMainFrame = &dummyFrameLoaderClient.get();
 }
 
 class EmptyPopupMenu : public PopupMenu {