IndexedDB: leak WebIDBConnectionToServer in layout tests
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2019 18:51:19 +0000 (18:51 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Feb 2019 18:51:19 +0000 (18:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193688
<rdar://problem/47353263>

Reviewed by Geoffrey Garen.

Source/WebCore:

Let IDBConnectionToServer keep a WeakPtr of IDBConnectionToServerDelegate.

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::IDBConnectionToServer):
* Modules/indexeddb/client/IDBConnectionToServer.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:

Source/WebKit:

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::didClose):
(WebKit::NetworkConnectionToWebProcess::establishIDBConnectionToServer):
(WebKit::NetworkConnectionToWebProcess::removeIDBConnectionToServer): Deleted.
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
(WebKit::WebIDBConnectionToServer::~WebIDBConnectionToServer):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in
Source/WebKit/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp

index 4700238..80acf87 100644 (file)
@@ -1,3 +1,18 @@
+2019-02-04  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: leak WebIDBConnectionToServer in layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193688
+        <rdar://problem/47353263>
+
+        Reviewed by Geoffrey Garen.
+
+        Let IDBConnectionToServer keep a WeakPtr of IDBConnectionToServerDelegate.
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::IDBConnectionToServer):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+
 2019-02-04  Youenn Fablet  <youenn@apple.com>
 
         Make sure to remove the device observer in AVVideoCaptureSource
index fb50f69..271a653 100644 (file)
@@ -48,7 +48,7 @@ Ref<IDBConnectionToServer> IDBConnectionToServer::create(IDBConnectionToServerDe
 }
 
 IDBConnectionToServer::IDBConnectionToServer(IDBConnectionToServerDelegate& delegate)
-    : m_delegate(delegate)
+    : m_delegate(makeWeakPtr(delegate))
     , m_proxy(std::make_unique<IDBConnectionProxy>(*this))
 {
 }
index 851c342..9cb140d 100644 (file)
@@ -146,7 +146,7 @@ private:
     typedef void (IDBConnectionToServer::*ResultFunction)(const IDBResultData&);
     void callResultFunctionWithErrorLater(ResultFunction, const IDBResourceIdentifier& requestIdentifier);
     
-    Ref<IDBConnectionToServerDelegate> m_delegate;
+    WeakPtr<IDBConnectionToServerDelegate> m_delegate;
     bool m_serverConnectionIsValid { true };
 
     HashMap<uint64_t, WTF::Function<void (const Vector<String>&)>> m_getAllDatabaseNamesCallbacks;
index f217926..2862cbd 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -53,7 +54,7 @@ struct IDBKeyRangeData;
 
 namespace IDBClient {
 
-class IDBConnectionToServerDelegate {
+class IDBConnectionToServerDelegate : public CanMakeWeakPtr<IDBConnectionToServerDelegate> {
 public:
     virtual ~IDBConnectionToServerDelegate() = default;
 
index 00daff7..48fb3b1 100644 (file)
@@ -1,3 +1,20 @@
+2019-02-04  Sihui Liu  <sihui_liu@apple.com>
+
+        IndexedDB: leak WebIDBConnectionToServer in layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193688
+        <rdar://problem/47353263>
+
+        Reviewed by Geoffrey Garen.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::didClose):
+        (WebKit::NetworkConnectionToWebProcess::establishIDBConnectionToServer):
+        (WebKit::NetworkConnectionToWebProcess::removeIDBConnectionToServer): Deleted.
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
+        (WebKit::WebIDBConnectionToServer::~WebIDBConnectionToServer):
+
 2019-02-04  Antoine Quint  <graouts@apple.com>
 
         <rdar://problem/47788802>
index 5db4b6d..b20c645 100644 (file)
@@ -263,7 +263,7 @@ void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection)
     auto idbConnections = m_webIDBConnections;
     for (auto& connection : idbConnections.values())
         connection->disconnectedFromWebProcess();
-    
+
     m_webIDBConnections.clear();
 #endif
     
@@ -753,14 +753,6 @@ void NetworkConnectionToWebProcess::establishIDBConnectionToServer(PAL::SessionI
     
     m_webIDBConnections.set(serverConnectionIdentifier, WebIDBConnectionToClient::create(m_networkProcess, m_connection.get(), serverConnectionIdentifier, sessionID));
 }
-
-void NetworkConnectionToWebProcess::removeIDBConnectionToServer(uint64_t serverConnectionIdentifier)
-{
-    ASSERT(m_webIDBConnections.contains(serverConnectionIdentifier));
-    
-    auto connection = m_webIDBConnections.take(serverConnectionIdentifier);
-    connection->disconnectedFromWebProcess();
-}
 #endif
     
 #if ENABLE(SERVICE_WORKER)
index 914d7bd..b820258 100644 (file)
@@ -175,7 +175,6 @@ private:
 #if ENABLE(INDEXED_DATABASE)
     // Messages handlers (Modern IDB).
     void establishIDBConnectionToServer(PAL::SessionID, uint64_t& serverConnectionIdentifier);
-    void removeIDBConnectionToServer(uint64_t serverConnectionIdentifier);
 #endif
 
 #if ENABLE(SERVICE_WORKER)
index 0496096..67afabb 100644 (file)
@@ -79,7 +79,6 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
 
 #if ENABLE(INDEXED_DATABASE)
     EstablishIDBConnectionToServer(PAL::SessionID sessionID) -> (uint64_t serverConnectionIdentifier) LegacySync
-    RemoveIDBConnectionToServer(uint64_t serverConnectionIdentifier)
 #endif
 
 #if ENABLE(SERVICE_WORKER)
index 42e73c8..f352200 100644 (file)
@@ -64,14 +64,11 @@ WebIDBConnectionToServer::WebIDBConnectionToServer(PAL::SessionID sessionID)
 
     m_isOpenInServer = sendSync(Messages::NetworkConnectionToWebProcess::EstablishIDBConnectionToServer(sessionID), Messages::NetworkConnectionToWebProcess::EstablishIDBConnectionToServer::Reply(m_identifier));
 
-    // FIXME: This creates a reference cycle, so neither this object nor the IDBConnectionToServer will ever be deallocated.
     m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
 }
 
 WebIDBConnectionToServer::~WebIDBConnectionToServer()
 {
-    if (m_isOpenInServer)
-        send(Messages::NetworkConnectionToWebProcess::RemoveIDBConnectionToServer(m_identifier));
 }
 
 IPC::Connection* WebIDBConnectionToServer::messageSenderConnection()