IndexedDatabase Server thread in com.apple.WebKit.Networking process leaks objects...
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 May 2019 22:07:24 +0000 (22:07 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 May 2019 22:07:24 +0000 (22:07 +0000)
<https://webkit.org/b/198346>
<rdar://problem/50895658>

Reviewed by Brent Fulgham.

Source/WebCore:

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::IDBServer):
- Pass AutodrainedPoolForRunLoop::Use when creating
  CrossThreadTaskHandler to fix the bug.

Source/WTF:

* wtf/CrossThreadTaskHandler.cpp:
(WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
- Add optional second argument to enable use of an
  AutodrainedPool when running the runloop.
(WTF::CrossThreadTaskHandler::taskRunLoop):
- Create an AutodrainedPool if requested when
  CrossThreadTaskHandler was created.
* wtf/CrossThreadTaskHandler.h:
(WTF::CrossThreadTaskHandler::AutodrainedPoolForRunLoop):
- Add enum class for enabling an AutodrainedPool for
  CrossThreadTaskHandler::taskRunLoop().
(WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
- Add optional second argument to enable use of an
  AutodrainedPool when running the runloop.

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

Source/WTF/ChangeLog
Source/WTF/wtf/CrossThreadTaskHandler.cpp
Source/WTF/wtf/CrossThreadTaskHandler.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp

index c66e793..94f2783 100644 (file)
@@ -1,3 +1,26 @@
+2019-05-29  David Kilzer  <ddkilzer@apple.com>
+
+        IndexedDatabase Server thread in com.apple.WebKit.Networking process leaks objects into an autoreleasePool that's never cleared
+        <https://webkit.org/b/198346>
+        <rdar://problem/50895658>
+
+        Reviewed by Brent Fulgham.
+
+        * wtf/CrossThreadTaskHandler.cpp:
+        (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+        - Add optional second argument to enable use of an
+          AutodrainedPool when running the runloop.
+        (WTF::CrossThreadTaskHandler::taskRunLoop):
+        - Create an AutodrainedPool if requested when
+          CrossThreadTaskHandler was created.
+        * wtf/CrossThreadTaskHandler.h:
+        (WTF::CrossThreadTaskHandler::AutodrainedPoolForRunLoop):
+        - Add enum class for enabling an AutodrainedPool for
+          CrossThreadTaskHandler::taskRunLoop().
+        (WTF::CrossThreadTaskHandler::CrossThreadTaskHandler):
+        - Add optional second argument to enable use of an
+          AutodrainedPool when running the runloop.
+
 2019-05-29  Geoffrey Garen  <ggaren@apple.com>
 
         WeakPtr breaks vtables when upcasting to base classes
index 45ec041..83c2075 100644 (file)
 #include "config.h"
 #include <wtf/CrossThreadTaskHandler.h>
 
+#include <wtf/AutodrainedPool.h>
+
 namespace WTF {
 
-CrossThreadTaskHandler::CrossThreadTaskHandler(const char* threadName)
+CrossThreadTaskHandler::CrossThreadTaskHandler(const char* threadName, AutodrainedPoolForRunLoop useAutodrainedPool)
+    : m_useAutodrainedPool(useAutodrainedPool)
 {
     ASSERT(isMainThread());
     Locker<Lock> locker(m_taskThreadCreationLock);
@@ -69,7 +72,11 @@ void CrossThreadTaskHandler::taskRunLoop()
     }
 
     while (!m_taskQueue.isKilled()) {
-        m_taskQueue.waitForMessage().performTask();
+        {
+            std::unique_ptr<AutodrainedPool> autodrainedPool = (m_useAutodrainedPool == AutodrainedPoolForRunLoop::Use) ? std::make_unique<AutodrainedPool>() : nullptr;
+
+            m_taskQueue.waitForMessage().performTask();
+        }
 
         Locker<Lock> shouldSuspendLocker(m_shouldSuspendLock);
         while (m_shouldSuspend) {
index f054601..1460ae7 100644 (file)
@@ -38,9 +38,10 @@ class SQLiteDatabase;
 class CrossThreadTaskHandler {
 public:
     WTF_EXPORT_PRIVATE virtual ~CrossThreadTaskHandler();
+    enum class AutodrainedPoolForRunLoop { DoNotUse, Use };
 
 protected:
-    WTF_EXPORT_PRIVATE CrossThreadTaskHandler(const char* threadName);
+    WTF_EXPORT_PRIVATE CrossThreadTaskHandler(const char* threadName, AutodrainedPoolForRunLoop = AutodrainedPoolForRunLoop::DoNotUse);
 
     WTF_EXPORT_PRIVATE void postTask(CrossThreadTask&&);
     WTF_EXPORT_PRIVATE void postTaskReply(CrossThreadTask&&);
@@ -51,6 +52,8 @@ private:
     void handleTaskRepliesOnMainThread();
     void taskRunLoop();
 
+    AutodrainedPoolForRunLoop m_useAutodrainedPool { AutodrainedPoolForRunLoop::DoNotUse };
+
     Lock m_taskThreadCreationLock;
     Lock m_mainThreadReplyLock;
     bool m_mainThreadReplyScheduled { false };
index cce9f6e..a926850 100644 (file)
@@ -1,3 +1,16 @@
+2019-05-29  David Kilzer  <ddkilzer@apple.com>
+
+        IndexedDatabase Server thread in com.apple.WebKit.Networking process leaks objects into an autoreleasePool that's never cleared
+        <https://webkit.org/b/198346>
+        <rdar://problem/50895658>
+
+        Reviewed by Brent Fulgham.
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::IDBServer):
+        - Pass AutodrainedPoolForRunLoop::Use when creating
+          CrossThreadTaskHandler to fix the bug.
+
 2019-05-29  Geoffrey Garen  <ggaren@apple.com>
 
         WeakPtr breaks vtables when upcasting to base classes
index 054b7e2..7f0709d 100644 (file)
@@ -57,7 +57,7 @@ Ref<IDBServer> IDBServer::create(PAL::SessionID sessionID, const String& databas
 }
 
 IDBServer::IDBServer(PAL::SessionID sessionID, IDBBackingStoreTemporaryFileHandler& fileHandler, QuotaManagerGetter&& quotaManagerGetter)
-    : CrossThreadTaskHandler("IndexedDatabase Server")
+    : CrossThreadTaskHandler("IndexedDatabase Server", AutodrainedPoolForRunLoop::Use)
     , m_sessionID(sessionID)
     , m_backingStoreTemporaryFileHandler(fileHandler)
     , m_quotaManagerGetter(WTFMove(quotaManagerGetter))
@@ -65,7 +65,7 @@ IDBServer::IDBServer(PAL::SessionID sessionID, IDBBackingStoreTemporaryFileHandl
 }
 
 IDBServer::IDBServer(PAL::SessionID sessionID, const String& databaseDirectoryPath, IDBBackingStoreTemporaryFileHandler& fileHandler, QuotaManagerGetter&& quotaManagerGetter)
-    : CrossThreadTaskHandler("IndexedDatabase Server")
+    : CrossThreadTaskHandler("IndexedDatabase Server", AutodrainedPoolForRunLoop::Use)
     , m_sessionID(sessionID)
     , m_databaseDirectoryPath(databaseDirectoryPath)
     , m_backingStoreTemporaryFileHandler(fileHandler)