diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index 6ab40a66ad..b27a527477 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -415,13 +415,6 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { role_conflict_(false), ports_destroyed_(0) {} - ~PortTest() { - // Workaround for tests that trigger async destruction of objects that we - // need to give an opportunity here to run, before proceeding with other - // teardown. - rtc::Thread::Current()->ProcessMessages(0); - } - protected: std::string password() { return password_; } diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc index 307d499255..aaf6c19b82 100644 --- a/rtc_base/thread.cc +++ b/rtc_base/thread.cc @@ -1223,6 +1223,11 @@ AutoSocketServerThread::AutoSocketServerThread(SocketServer* ss) AutoSocketServerThread::~AutoSocketServerThread() { RTC_DCHECK(ThreadManager::Instance()->CurrentThread() == this); + // Some tests post destroy messages to this thread. To avoid memory + // leaks, we have to process those messages. In particular + // P2PTransportChannelPingTest, relying on the message posted in + // cricket::Connection::Destroy. + ProcessMessages(0); // Stop and destroy the thread before clearing it as the current thread. // Sometimes there are messages left in the Thread that will be // destroyed by DoDestroy, and sometimes the destructors of the message and/or