Bug 1185478: Add leak checks to socket I/O classes
authorThomas Zimmermann <tdz@users.sourceforge.net>
Tue, 21 Jul 2015 08:06:29 +0200
changeset 253778 e9f9b39c43317d8de56a49427ccbdf27b9647ad0
parent 253777 d8d8bf8cfb9a7acd1ff017b28164fc00f0a07d6f
child 253779 ab33eac30c5dd699f92fadfd6005253ecf139838
push id29079
push usercbook@mozilla.com
push dateTue, 21 Jul 2015 14:50:24 +0000
treeherdermozilla-central@27d4a5eb76e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1185478
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1185478: Add leak checks to socket I/O classes
dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
dom/bluetooth/bluedroid/BluetoothSocket.cpp
dom/bluetooth/bluedroid/BluetoothSocket.h
dom/bluetooth/bluez/BluetoothSocket.cpp
dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
ipc/hal/DaemonSocket.cpp
ipc/hal/DaemonSocketPDU.cpp
ipc/keystore/KeyStoreConnector.cpp
ipc/nfc/NfcConnector.cpp
ipc/ril/RilConnector.cpp
ipc/ril/RilSocket.cpp
ipc/unixsocket/ConnectionOrientedSocket.cpp
ipc/unixsocket/ConnectionOrientedSocket.h
ipc/unixsocket/DataSocket.cpp
ipc/unixsocket/DataSocket.h
ipc/unixsocket/ListenSocket.cpp
ipc/unixsocket/ListenSocket.h
ipc/unixsocket/SocketBase.cpp
ipc/unixsocket/SocketBase.h
ipc/unixsocket/StreamSocket.cpp
ipc/unixsocket/UnixSocketConnector.cpp
--- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp
@@ -3,27 +3,32 @@
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BluetoothDaemonConnector.h"
 #include <fcntl.h>
 #include <sys/un.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsThreadUtils.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 BluetoothDaemonConnector::BluetoothDaemonConnector(
   const nsACString& aSocketName)
   : mSocketName(aSocketName)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(BluetoothDaemonConnector, UnixSocketConnector);
+}
 
 BluetoothDaemonConnector::~BluetoothDaemonConnector()
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(BluetoothDaemonConnector, UnixSocketConnector);
+}
 
 nsresult
 BluetoothDaemonConnector::CreateSocket(int& aFd) const
 {
   aFd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
   if (aFd < 0) {
     BT_WARNING("Could not open Bluetooth daemon socket!");
     return NS_ERROR_FAILURE;
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp
@@ -8,16 +8,17 @@
 #include <fcntl.h>
 #include <sys/socket.h>
 #include "BluetoothSocketObserver.h"
 #include "BluetoothInterface.h"
 #include "BluetoothUtils.h"
 #include "mozilla/ipc/UnixSocketWatcher.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/RefPtr.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsXULAppAPI.h"
 
 using namespace mozilla::ipc;
 USING_BLUETOOTH_NAMESPACE
 
 static const size_t MAX_READ_SIZE = 1 << 16;
 static BluetoothSocketInterface* sBluetoothSocketInterface;
 
@@ -73,21 +74,25 @@ public:
   DroidSocketImpl(MessageLoop* aConsumerLoop,
                   MessageLoop* aIOLoop,
                   BluetoothSocket* aConsumer)
     : ipc::UnixFdWatcher(aIOLoop)
     , DataSocketIO(aConsumerLoop)
     , mConsumer(aConsumer)
     , mShuttingDownOnIOThread(false)
     , mConnectionStatus(SOCKET_IS_DISCONNECTED)
-  { }
+  {
+    MOZ_COUNT_CTOR_INHERITED(DroidSocketImpl, DataSocketIO);
+  }
 
   ~DroidSocketImpl()
   {
     MOZ_ASSERT(IsConsumerThread());
+
+    MOZ_COUNT_DTOR_INHERITED(DroidSocketImpl, DataSocketIO);
   }
 
   void Send(UnixSocketIOBuffer* aBuffer)
   {
     EnqueueData(aBuffer);
     AddWatchers(WRITE_WATCHER, false);
   }
 
@@ -577,20 +582,27 @@ DroidSocketImpl::DiscardBuffer()
 
 BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
   : mObserver(aObserver)
   , mCurrentRes(nullptr)
   , mImpl(nullptr)
 {
   MOZ_ASSERT(aObserver);
 
+  MOZ_COUNT_CTOR_INHERITED(BluetoothSocket, DataSocket);
+
   EnsureBluetoothSocketHalLoad();
   mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
 }
 
+BluetoothSocket::~BluetoothSocket()
+{
+  MOZ_COUNT_DTOR_INHERITED(BluetoothSocket, DataSocket);
+}
+
 class ConnectSocketResultHandler final : public BluetoothSocketResultHandler
 {
 public:
   ConnectSocketResultHandler(DroidSocketImpl* aImpl)
   : mImpl(aImpl)
   {
     MOZ_ASSERT(mImpl);
   }
--- a/dom/bluetooth/bluedroid/BluetoothSocket.h
+++ b/dom/bluetooth/bluedroid/BluetoothSocket.h
@@ -17,16 +17,17 @@ BEGIN_BLUETOOTH_NAMESPACE
 class BluetoothSocketObserver;
 class BluetoothSocketResultHandler;
 class DroidSocketImpl;
 
 class BluetoothSocket final : public mozilla::ipc::DataSocket
 {
 public:
   BluetoothSocket(BluetoothSocketObserver* aObserver);
+  ~BluetoothSocket();
 
   nsresult Connect(const nsAString& aDeviceAddress,
                    const BluetoothUuid& aServiceUuid,
                    BluetoothSocketType aType,
                    int aChannel,
                    bool aAuth, bool aEncrypt,
                    MessageLoop* aConsumerLoop,
                    MessageLoop* aIOLoop);
--- a/dom/bluetooth/bluez/BluetoothSocket.cpp
+++ b/dom/bluetooth/bluez/BluetoothSocket.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BluetoothSocket.h"
 #include <fcntl.h>
 #include "BluetoothSocketObserver.h"
 #include "BluetoothUnixSocketConnector.h"
 #include "mozilla/RefPtr.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsXULAppAPI.h"
 
 using namespace mozilla::ipc;
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 static const size_t MAX_READ_SIZE = 1 << 16;
 
@@ -141,22 +142,26 @@ BluetoothSocket::BluetoothSocketIO::Blue
   , mConsumer(aConsumer)
   , mConnector(aConnector)
   , mShuttingDownOnIOThread(false)
   , mAddressLength(0)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mConsumer);
   MOZ_ASSERT(mConnector);
+
+  MOZ_COUNT_CTOR_INHERITED(BluetoothSocketIO, DataSocketIO);
 }
 
 BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO()
 {
   MOZ_ASSERT(IsConsumerThread());
   MOZ_ASSERT(IsShutdownOnConsumerThread());
+
+  MOZ_COUNT_DTOR_INHERITED(BluetoothSocketIO, DataSocketIO);
 }
 
 void
 BluetoothSocket::BluetoothSocketIO::GetSocketAddr(nsAString& aAddrStr) const
 {
   if (!mConnector) {
     NS_WARNING("No connector to get socket address from!");
     aAddrStr.Truncate();
@@ -557,21 +562,25 @@ public:
 // BluetoothSocket
 //
 
 BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver)
   : mObserver(aObserver)
   , mIO(nullptr)
 {
   MOZ_ASSERT(aObserver);
+
+  MOZ_COUNT_CTOR_INHERITED(BluetoothSocket, DataSocket);
 }
 
 BluetoothSocket::~BluetoothSocket()
 {
   MOZ_ASSERT(!mIO);
+
+  MOZ_COUNT_DTOR_INHERITED(BluetoothSocket, DataSocket);
 }
 
 nsresult
 BluetoothSocket::Connect(const nsAString& aDeviceAddress,
                          const BluetoothUuid& aServiceUuid,
                          BluetoothSocketType aType,
                          int aChannel,
                          bool aAuth, bool aEncrypt)
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
+++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp
@@ -25,16 +25,17 @@
 #include <bluetooth/l2cap.h>
 #include <bluetooth/rfcomm.h>
 #include <bluetooth/sco.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 using namespace mozilla::ipc;
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 static const int RFCOMM_SO_SNDBUF = 70 * 1024;  // 70 KB send buffer
 static const int L2CAP_SO_SNDBUF = 400 * 1024;  // 400 KB send buffer
@@ -47,20 +48,24 @@ BluetoothUnixSocketConnector::BluetoothU
   int aChannel,
   bool aAuth,
   bool aEncrypt)
   : mAddressString(aAddressString)
   , mType(aType)
   , mChannel(aChannel)
   , mAuth(aAuth)
   , mEncrypt(aEncrypt)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(BluetoothUnixSocketConnector, UnixSocketConnector);
+}
 
 BluetoothUnixSocketConnector::~BluetoothUnixSocketConnector()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(BluetoothUnixSocketConnector, UnixSocketConnector);
+}
 
 nsresult
 BluetoothUnixSocketConnector::CreateSocket(int& aFd) const
 {
   static const int sType[] = {
     [0] = 0,
     [BluetoothSocketType::RFCOMM] = SOCK_STREAM,
     [BluetoothSocketType::SCO] = SOCK_SEQPACKET,
--- a/ipc/hal/DaemonSocket.cpp
+++ b/ipc/hal/DaemonSocket.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DaemonSocket.h"
 #include "mozilla/ipc/DaemonSocketConsumer.h"
 #include "mozilla/ipc/DaemonSocketPDU.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 
 #ifdef CHROMIUM_LOG
 #undef CHROMIUM_LOG
 #endif
 
 #if defined(MOZ_WIDGET_GONK)
 #include <android/log.h>
 #define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "I/O", args);
@@ -33,16 +34,18 @@ class DaemonSocketIO final : public Conn
 public:
   DaemonSocketIO(MessageLoop* aConsumerLoop,
                  MessageLoop* aIOLoop,
                  int aFd, ConnectionStatus aConnectionStatus,
                  UnixSocketConnector* aConnector,
                  DaemonSocket* aConnection,
                  DaemonSocketIOConsumer* aConsumer);
 
+  ~DaemonSocketIO();
+
   // Methods for |DataSocketIO|
   //
 
   nsresult QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer) override;
   void ConsumeBuffer() override;
   void DiscardBuffer() override;
 
   // Methods for |SocketIOBase|
@@ -77,16 +80,23 @@ DaemonSocketIO::DaemonSocketIO(
                                aConnectionStatus,
                                aConnector)
   , mConnection(aConnection)
   , mConsumer(aConsumer)
   , mShuttingDownOnIOThread(false)
 {
   MOZ_ASSERT(mConnection);
   MOZ_ASSERT(mConsumer);
+
+  MOZ_COUNT_CTOR_INHERITED(DaemonSocketIO, ConnectionOrientedSocketIO);
+}
+
+DaemonSocketIO::~DaemonSocketIO()
+{
+  MOZ_COUNT_DTOR_INHERITED(DaemonSocketIO, ConnectionOrientedSocketIO);
 }
 
 // |DataSocketIO|
 
 nsresult
 DaemonSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
 {
   MOZ_ASSERT(aBuffer);
@@ -164,20 +174,24 @@ DaemonSocket::DaemonSocket(
   DaemonSocketConsumer* aConsumer,
   int aIndex)
   : mIO(nullptr)
   , mIOConsumer(aIOConsumer)
   , mConsumer(aConsumer)
   , mIndex(aIndex)
 {
   MOZ_ASSERT(mConsumer);
+
+  MOZ_COUNT_CTOR_INHERITED(DaemonSocket, ConnectionOrientedSocket);
 }
 
 DaemonSocket::~DaemonSocket()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(DaemonSocket, ConnectionOrientedSocket);
+}
 
 // |ConnectionOrientedSocket|
 
 nsresult
 DaemonSocket::PrepareAccept(UnixSocketConnector* aConnector,
                             MessageLoop* aConsumerLoop,
                             MessageLoop* aIOLoop,
                             ConnectionOrientedSocketIO*& aIO)
--- a/ipc/hal/DaemonSocketPDU.cpp
+++ b/ipc/hal/DaemonSocketPDU.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DaemonSocketPDU.h"
 #include "mozilla/ipc/DaemonSocketConsumer.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 
 #ifdef CHROMIUM_LOG
 #undef CHROMIUM_LOG
 #endif
 
 #if defined(MOZ_WIDGET_GONK)
 #include <android/log.h>
 #define CHROMIUM_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "I/O", args);
@@ -27,16 +28,18 @@ namespace ipc {
 // DaemonSocketPDU
 //
 
 DaemonSocketPDU::DaemonSocketPDU(uint8_t aService, uint8_t aOpcode,
                                        uint16_t aPayloadSize)
   : mConsumer(nullptr)
   , mUserData(nullptr)
 {
+  MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer);
+
   // Allocate memory
   size_t availableSpace = HEADER_SIZE + aPayloadSize;
   ResetBuffer(new uint8_t[availableSpace], 0, 0, availableSpace);
 
   // Reserve PDU header
   uint8_t* data = Append(HEADER_SIZE);
   MOZ_ASSERT(data);
 
@@ -45,22 +48,26 @@ DaemonSocketPDU::DaemonSocketPDU(uint8_t
   data[OFF_OPCODE] = aOpcode;
   memcpy(data + OFF_LENGTH, &aPayloadSize, sizeof(aPayloadSize));
 }
 
 DaemonSocketPDU::DaemonSocketPDU(size_t aPayloadSize)
   : mConsumer(nullptr)
   , mUserData(nullptr)
 {
+  MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer);
+
   size_t availableSpace = HEADER_SIZE + aPayloadSize;
   ResetBuffer(new uint8_t[availableSpace], 0, 0, availableSpace);
 }
 
 DaemonSocketPDU::~DaemonSocketPDU()
 {
+  MOZ_COUNT_DTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer);
+
   nsAutoArrayPtr<uint8_t> data(GetBuffer());
   ResetBuffer(nullptr, 0, 0, 0);
 }
 
 void
 DaemonSocketPDU::GetHeader(uint8_t& aService, uint8_t& aOpcode,
                               uint16_t& aPayloadSize)
 {
--- a/ipc/keystore/KeyStoreConnector.cpp
+++ b/ipc/keystore/KeyStoreConnector.cpp
@@ -5,36 +5,41 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "KeyStoreConnector.h"
 #include <fcntl.h>
 #include <pwd.h>
 #include <sys/stat.h>
 #include <sys/un.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 #ifdef MOZ_WIDGET_GONK
 #include <android/log.h>
 #define KEYSTORE_LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
 #else
 #define KEYSTORE_LOG(args...)  printf(args);
 #endif
 
 namespace mozilla {
 namespace ipc {
 
 static const char KEYSTORE_SOCKET_PATH[] = "/dev/socket/keystore";
 
 KeyStoreConnector::KeyStoreConnector(const char** const aAllowedUsers)
   : mAllowedUsers(aAllowedUsers)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(KeyStoreConnector, UnixSocketConnector);
+}
 
 KeyStoreConnector::~KeyStoreConnector()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(KeyStoreConnector, UnixSocketConnector);
+}
 
 nsresult
 KeyStoreConnector::CreateSocket(int& aFd) const
 {
   unlink(KEYSTORE_SOCKET_PATH);
 
   aFd = socket(AF_LOCAL, SOCK_STREAM, 0);
   if (aFd < 0) {
--- a/ipc/nfc/NfcConnector.cpp
+++ b/ipc/nfc/NfcConnector.cpp
@@ -3,27 +3,32 @@
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "NfcConnector.h"
 #include <fcntl.h>
 #include <sys/un.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 namespace mozilla {
 namespace ipc {
 
 NfcConnector::NfcConnector(const nsACString& aAddressString)
   : mAddressString(aAddressString)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(NfcConnector, UnixSocketConnector);
+}
 
 NfcConnector::~NfcConnector()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(NfcConnector, UnixSocketConnector);
+}
 
 nsresult
 NfcConnector::CreateSocket(int& aFd) const
 {
   aFd = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
   if (aFd < 0) {
     NS_WARNING("Could not open NFC socket!");
     return NS_ERROR_FAILURE;
--- a/ipc/ril/RilConnector.cpp
+++ b/ipc/ril/RilConnector.cpp
@@ -3,16 +3,17 @@
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RilConnector.h"
 #include <fcntl.h>
 #include <sys/socket.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsThreadUtils.h" // For NS_IsMainThread.
 
 #ifdef AF_INET
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #endif
 #ifdef AF_UNIX
 #include <sys/un.h>
@@ -22,20 +23,24 @@ namespace mozilla {
 namespace ipc {
 
 static const uint16_t RIL_TEST_PORT = 6200;
 
 RilConnector::RilConnector(const nsACString& aAddressString,
                            unsigned long aClientId)
   : mAddressString(aAddressString)
   , mClientId(aClientId)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(RilConnector, UnixSocketConnector);
+}
 
 RilConnector::~RilConnector()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(RilConnector, UnixSocketConnector);
+}
 
 nsresult
 RilConnector::CreateSocket(int aDomain, int& aFd) const
 {
   aFd = socket(aDomain, SOCK_STREAM, 0);
   if (aFd < 0) {
     NS_WARNING("Could not open RIL socket!");
     return NS_ERROR_FAILURE;
--- a/ipc/ril/RilSocket.cpp
+++ b/ipc/ril/RilSocket.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RilSocket.h"
 #include <fcntl.h>
 #include "mozilla/dom/workers/Workers.h"
 #include "mozilla/ipc/UnixSocketConnector.h"
 #include "mozilla/RefPtr.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsXULAppAPI.h"
 #include "RilSocketConsumer.h"
 
 static const size_t MAX_READ_SIZE = 1 << 16;
 
 namespace mozilla {
 namespace ipc {
 
@@ -103,22 +104,26 @@ RilSocketIO::RilSocketIO(WorkerCrossThre
   : ConnectionOrientedSocketIO(aConsumerLoop, aIOLoop, aConnector)
   , mDispatcher(aDispatcher)
   , mRilSocket(aRilSocket)
   , mShuttingDownOnIOThread(false)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mDispatcher);
   MOZ_ASSERT(mRilSocket);
+
+  MOZ_COUNT_CTOR_INHERITED(RilSocketIO, ConnectionOrientedSocketIO);
 }
 
 RilSocketIO::~RilSocketIO()
 {
   MOZ_ASSERT(IsConsumerThread());
   MOZ_ASSERT(IsShutdownOnConsumerThread());
+
+  MOZ_COUNT_DTOR_INHERITED(RilSocketIO, ConnectionOrientedSocketIO);
 }
 
 RilSocket*
 RilSocketIO::GetRilSocket()
 {
   return mRilSocket.get();
 }
 
@@ -319,21 +324,25 @@ RilSocket::RilSocket(WorkerCrossThreadDi
                      RilSocketConsumer* aConsumer, int aIndex)
   : mIO(nullptr)
   , mDispatcher(aDispatcher)
   , mConsumer(aConsumer)
   , mIndex(aIndex)
 {
   MOZ_ASSERT(mDispatcher);
   MOZ_ASSERT(mConsumer);
+
+  MOZ_COUNT_CTOR_INHERITED(RilSocket, ConnectionOrientedSocket);
 }
 
 RilSocket::~RilSocket()
 {
   MOZ_ASSERT(!mIO);
+
+  MOZ_COUNT_DTOR_INHERITED(RilSocket, ConnectionOrientedSocket);
 }
 
 void
 RilSocket::ReceiveSocketData(JSContext* aCx,
                              nsAutoPtr<UnixSocketBuffer>& aBuffer)
 {
   mConsumer->ReceiveSocketData(aCx, mIndex, aBuffer);
 }
--- a/ipc/unixsocket/ConnectionOrientedSocket.cpp
+++ b/ipc/unixsocket/ConnectionOrientedSocket.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ConnectionOrientedSocket.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "UnixSocketConnector.h"
 
 namespace mozilla {
 namespace ipc {
 
 //
 // ConnectionOrientedSocketIO
 //
@@ -20,32 +21,38 @@ ConnectionOrientedSocketIO::ConnectionOr
   int aFd, ConnectionStatus aConnectionStatus,
   UnixSocketConnector* aConnector)
   : DataSocketIO(aConsumerLoop)
   , UnixSocketWatcher(aIOLoop, aFd, aConnectionStatus)
   , mConnector(aConnector)
   , mPeerAddressLength(0)
 {
   MOZ_ASSERT(mConnector);
+
+  MOZ_COUNT_CTOR_INHERITED(ConnectionOrientedSocketIO, DataSocketIO);
 }
 
 ConnectionOrientedSocketIO::ConnectionOrientedSocketIO(
   MessageLoop* aConsumerLoop,
   MessageLoop* aIOLoop,
   UnixSocketConnector* aConnector)
   : DataSocketIO(aConsumerLoop)
   , UnixSocketWatcher(aIOLoop)
   , mConnector(aConnector)
   , mPeerAddressLength(0)
 {
   MOZ_ASSERT(mConnector);
+
+  MOZ_COUNT_CTOR_INHERITED(ConnectionOrientedSocketIO, DataSocketIO);
 }
 
 ConnectionOrientedSocketIO::~ConnectionOrientedSocketIO()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(ConnectionOrientedSocketIO, DataSocketIO);
+}
 
 nsresult
 ConnectionOrientedSocketIO::Accept(int aFd,
                                    const struct sockaddr* aPeerAddress,
                                    socklen_t aPeerAddressLength)
 {
   MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
   MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTING);
@@ -176,13 +183,20 @@ ConnectionOrientedSocketIO::OnError(cons
   GetConsumerThread()->PostTask(
     FROM_HERE, new SocketEventTask(this, SocketEventTask::CONNECT_ERROR));
 }
 
 //
 // ConnectionOrientedSocket
 //
 
+ConnectionOrientedSocket::ConnectionOrientedSocket()
+{
+  MOZ_COUNT_CTOR_INHERITED(ConnectionOrientedSocket, DataSocket);
+}
+
 ConnectionOrientedSocket::~ConnectionOrientedSocket()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(ConnectionOrientedSocket, DataSocket);
+}
 
 }
 }
--- a/ipc/unixsocket/ConnectionOrientedSocket.h
+++ b/ipc/unixsocket/ConnectionOrientedSocket.h
@@ -1,16 +1,16 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef mozilla_ipc_connectionorientedsocket_h
-#define mozilla_ipc_connectionorientedsocket_h
+#ifndef mozilla_ipc_ConnectionOrientedSocket_h
+#define mozilla_ipc_ConnectionOrientedSocket_h
 
 #include <sys/socket.h>
 #include "DataSocket.h"
 #include "mozilla/ipc/UnixSocketWatcher.h"
 
 class MessageLoop;
 
 namespace mozilla {
@@ -107,15 +107,16 @@ public:
    * @return NS_OK on success, or an XPCOM error code otherwise.
    */
   virtual nsresult PrepareAccept(UnixSocketConnector* aConnector,
                                  MessageLoop* aConsumerLoop,
                                  MessageLoop* aIOLoop,
                                  ConnectionOrientedSocketIO*& aIO) = 0;
 
 protected:
+  ConnectionOrientedSocket();
   virtual ~ConnectionOrientedSocket();
 };
 
 }
 }
 
-#endif
+#endif // mozilla_ipc_ConnectionOrientedSocket
--- a/ipc/unixsocket/DataSocket.cpp
+++ b/ipc/unixsocket/DataSocket.cpp
@@ -1,34 +1,37 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include "mozilla/ipc/DataSocket.h"
+#include "DataSocket.h"
 #ifdef MOZ_TASK_TRACER
 #include "GeckoTaskTracer.h"
 #endif
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 
 #ifdef MOZ_TASK_TRACER
 using namespace mozilla::tasktracer;
 #endif
 
 namespace mozilla {
 namespace ipc {
 
 //
 // DataSocketIO
 //
 
 DataSocketIO::~DataSocketIO()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(DataSocketIO, SocketIOBase);
+}
 
 void
 DataSocketIO::EnqueueData(UnixSocketIOBuffer* aBuffer)
 {
   if (!aBuffer->GetSize()) {
     delete aBuffer; // delete empty data immediately
     return;
   }
@@ -106,19 +109,28 @@ DataSocketIO::SendPendingData(int aFd)
     }
   }
 
   return NS_OK;
 }
 
 DataSocketIO::DataSocketIO(MessageLoop* aConsumerLoop)
   : SocketIOBase(aConsumerLoop)
-{ }
+{
+  MOZ_COUNT_CTOR_INHERITED(DataSocketIO, SocketIOBase);
+}
 
 //
 // DataSocket
 //
 
+DataSocket::DataSocket()
+{
+  MOZ_COUNT_CTOR_INHERITED(DataSocket, SocketBase);
+}
+
 DataSocket::~DataSocket()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(DataSocket, SocketBase);
+}
 
 }
 }
--- a/ipc/unixsocket/DataSocket.h
+++ b/ipc/unixsocket/DataSocket.h
@@ -31,16 +31,19 @@ public:
 
   /**
    * Queue data to be sent to the socket on the IO thread. Can only be called on
    * originating thread.
    *
    * @param aBuffer Data to be sent to socket
    */
   virtual void SendSocketData(UnixSocketIOBuffer* aBuffer) = 0;
+
+protected:
+  DataSocket();
 };
 
 //
 // DataSocketIO
 //
 
 /**
  * |DataSocketIO| is a base class for Socket I/O classes that
--- a/ipc/unixsocket/ListenSocket.cpp
+++ b/ipc/unixsocket/ListenSocket.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ListenSocket.h"
 #include <fcntl.h>
 #include "ConnectionOrientedSocket.h"
 #include "DataSocket.h"
 #include "ListenSocketConsumer.h"
 #include "mozilla/RefPtr.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsXULAppAPI.h"
 #include "UnixSocketConnector.h"
 
 namespace mozilla {
 namespace ipc {
 
 //
 // ListenSocketIO
@@ -104,22 +105,26 @@ ListenSocketIO::ListenSocketIO(MessageLo
   , mListenSocket(aListenSocket)
   , mConnector(aConnector)
   , mShuttingDownOnIOThread(false)
   , mAddressLength(0)
   , mCOSocketIO(nullptr)
 {
   MOZ_ASSERT(mListenSocket);
   MOZ_ASSERT(mConnector);
+
+  MOZ_COUNT_CTOR_INHERITED(ListenSocketIO, SocketIOBase);
 }
 
 ListenSocketIO::~ListenSocketIO()
 {
   MOZ_ASSERT(IsConsumerThread());
   MOZ_ASSERT(IsShutdownOnConsumerThread());
+
+  MOZ_COUNT_DTOR_INHERITED(ListenSocketIO, SocketIOBase);
 }
 
 UnixSocketConnector*
 ListenSocketIO::GetConnector() const
 {
   return mConnector;
 }
 
@@ -261,55 +266,65 @@ ListenSocketIO::ShutdownOnIOThread()
   Close(); // will also remove fd from I/O loop
   mShuttingDownOnIOThread = true;
 }
 
 //
 // Socket tasks
 //
 
-class ListenSocketIO::ListenTask final
-  : public SocketIOTask<ListenSocketIO>
+class ListenSocketIO::ListenTask final : public SocketIOTask<ListenSocketIO>
 {
 public:
   ListenTask(ListenSocketIO* aIO, ConnectionOrientedSocketIO* aCOSocketIO)
-  : SocketIOTask<ListenSocketIO>(aIO)
-  , mCOSocketIO(aCOSocketIO)
+    : SocketIOTask<ListenSocketIO>(aIO)
+    , mCOSocketIO(aCOSocketIO)
   {
     MOZ_ASSERT(mCOSocketIO);
+
+    MOZ_COUNT_CTOR(ListenTask);
+  }
+
+  ~ListenTask()
+  {
+    MOZ_COUNT_DTOR(ListenTask);
   }
 
   void Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
 
     if (!IsCanceled()) {
       GetIO()->Listen(mCOSocketIO);
     }
   }
 
 private:
   ConnectionOrientedSocketIO* mCOSocketIO;
 };
 
 //
-// UnixSocketConsumer
+// ListenSocket
 //
 
 ListenSocket::ListenSocket(ListenSocketConsumer* aConsumer, int aIndex)
   : mIO(nullptr)
   , mConsumer(aConsumer)
   , mIndex(aIndex)
 {
   MOZ_ASSERT(mConsumer);
+
+  MOZ_COUNT_CTOR_INHERITED(ListenSocket, SocketBase);
 }
 
 ListenSocket::~ListenSocket()
 {
   MOZ_ASSERT(!mIO);
+
+  MOZ_COUNT_DTOR_INHERITED(ListenSocket, SocketBase);
 }
 
 nsresult
 ListenSocket::Listen(UnixSocketConnector* aConnector,
                      MessageLoop* aConsumerLoop,
                      MessageLoop* aIOLoop,
                      ConnectionOrientedSocket* aCOSocket)
 {
--- a/ipc/unixsocket/ListenSocket.h
+++ b/ipc/unixsocket/ListenSocket.h
@@ -1,19 +1,19 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef mozilla_ipc_listensocket_h
-#define mozilla_ipc_listensocket_h
+#ifndef mozilla_ipc_ListenSocket_h
+#define mozilla_ipc_ListenSocket_h
 
+#include "mozilla/ipc/SocketBase.h"
 #include "nsString.h"
-#include "mozilla/ipc/SocketBase.h"
 
 class MessageLoop;
 
 namespace mozilla {
 namespace ipc {
 
 class ConnectionOrientedSocket;
 class ListenSocketConsumer;
@@ -85,9 +85,9 @@ private:
   ListenSocketIO* mIO;
   ListenSocketConsumer* mConsumer;
   int mIndex;
 };
 
 } // namespace ipc
 } // namepsace mozilla
 
-#endif // mozilla_ipc_listensocket_h
+#endif // mozilla_ipc_ListenSocket_h
--- a/ipc/unixsocket/SocketBase.cpp
+++ b/ipc/unixsocket/SocketBase.cpp
@@ -5,33 +5,38 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 #include "SocketBase.h"
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 
 namespace mozilla {
 namespace ipc {
 
 //
 // UnixSocketIOBuffer
 //
 
 UnixSocketBuffer::UnixSocketBuffer()
   : mSize(0)
   , mOffset(0)
   , mAvailableSpace(0)
   , mData(nullptr)
-{ }
+{
+  MOZ_COUNT_CTOR(UnixSocketBuffer);
+}
 
 UnixSocketBuffer::~UnixSocketBuffer()
 {
+  MOZ_COUNT_DTOR(UnixSocketBuffer);
+
   // Make sure that the caller released the buffer's memory.
   MOZ_ASSERT(!GetBuffer());
 }
 
 const uint8_t*
 UnixSocketBuffer::Consume(size_t aLen)
 {
   if (NS_WARN_IF(GetSize() < aLen)) {
@@ -91,38 +96,51 @@ UnixSocketBuffer::CleanupLeadingSpace()
     mOffset = 0;
   }
 }
 
 //
 // UnixSocketIOBuffer
 //
 
+UnixSocketIOBuffer::UnixSocketIOBuffer()
+{
+  MOZ_COUNT_CTOR_INHERITED(UnixSocketIOBuffer, UnixSocketBuffer);
+}
+
 UnixSocketIOBuffer::~UnixSocketIOBuffer()
-{ }
+{
+  MOZ_COUNT_DTOR_INHERITED(UnixSocketIOBuffer, UnixSocketBuffer);
+}
 
 //
 // UnixSocketRawData
 //
 
 UnixSocketRawData::UnixSocketRawData(const void* aData, size_t aSize)
 {
   MOZ_ASSERT(aData || !aSize);
 
+  MOZ_COUNT_CTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
+
   ResetBuffer(static_cast<uint8_t*>(memcpy(new uint8_t[aSize], aData, aSize)),
               0, aSize, aSize);
 }
 
 UnixSocketRawData::UnixSocketRawData(size_t aSize)
 {
+  MOZ_COUNT_CTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
+
   ResetBuffer(new uint8_t[aSize], 0, 0, aSize);
 }
 
 UnixSocketRawData::~UnixSocketRawData()
 {
+  MOZ_COUNT_DTOR_INHERITED(UnixSocketRawData, UnixSocketIOBuffer);
+
   nsAutoArrayPtr<uint8_t> data(GetBuffer());
   ResetBuffer(nullptr, 0, 0, 0);
 }
 
 ssize_t
 UnixSocketRawData::Receive(int aFd)
 {
   if (!GetTrailingSpace()) {
@@ -232,41 +250,49 @@ SocketBase::CalculateConnectDelayMs() co
   }
   return connectDelayMs;
 }
 
 SocketBase::SocketBase()
 : mConnectionStatus(SOCKET_DISCONNECTED)
 , mConnectTimestamp(0)
 , mConnectDelayMs(0)
-{ }
+{
+  MOZ_COUNT_CTOR(SocketBase);
+}
 
 SocketBase::~SocketBase()
 {
   MOZ_ASSERT(mConnectionStatus == SOCKET_DISCONNECTED);
+
+  MOZ_COUNT_DTOR(SocketBase);
 }
 
 void
 SocketBase::SetConnectionStatus(SocketConnectionStatus aConnectionStatus)
 {
   mConnectionStatus = aConnectionStatus;
 }
 
 //
 // SocketIOBase
 //
 
 SocketIOBase::SocketIOBase(MessageLoop* aConsumerLoop)
   : mConsumerLoop(aConsumerLoop)
 {
   MOZ_ASSERT(mConsumerLoop);
+
+  MOZ_COUNT_CTOR(SocketIOBase);
 }
 
 SocketIOBase::~SocketIOBase()
-{ }
+{
+  MOZ_COUNT_DTOR(SocketIOBase);
+}
 
 MessageLoop*
 SocketIOBase::GetConsumerThread() const
 {
   return mConsumerLoop;
 }
 
 bool
@@ -277,17 +303,24 @@ SocketIOBase::IsConsumerThread() const
 
 //
 // SocketEventTask
 //
 
 SocketEventTask::SocketEventTask(SocketIOBase* aIO, SocketEvent aEvent)
   : SocketTask<SocketIOBase>(aIO)
   , mEvent(aEvent)
-{ }
+{
+  MOZ_COUNT_CTOR(SocketEventTask);
+}
+
+SocketEventTask::~SocketEventTask()
+{
+  MOZ_COUNT_DTOR(SocketEventTask);
+}
 
 void
 SocketEventTask::Run()
 {
   SocketIOBase* io = SocketTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(io->IsConsumerThread());
 
@@ -308,20 +341,26 @@ SocketEventTask::Run()
     socketBase->NotifyDisconnect();
   }
 }
 
 //
 // SocketRequestClosingTask
 //
 
-SocketRequestClosingTask::SocketRequestClosingTask(
-  SocketIOBase* aIO)
+SocketRequestClosingTask::SocketRequestClosingTask(SocketIOBase* aIO)
   : SocketTask<SocketIOBase>(aIO)
-{ }
+{
+  MOZ_COUNT_CTOR(SocketRequestClosingTask);
+}
+
+SocketRequestClosingTask::~SocketRequestClosingTask()
+{
+  MOZ_COUNT_DTOR(SocketRequestClosingTask);
+}
 
 void
 SocketRequestClosingTask::Run()
 {
   SocketIOBase* io = SocketTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(io->IsConsumerThread());
 
@@ -336,34 +375,47 @@ SocketRequestClosingTask::Run()
 
   socketBase->Close();
 }
 
 //
 // SocketDeleteInstanceTask
 //
 
-SocketDeleteInstanceTask::SocketDeleteInstanceTask(
-  SocketIOBase* aIO)
+SocketDeleteInstanceTask::SocketDeleteInstanceTask(SocketIOBase* aIO)
   : mIO(aIO)
-{ }
+{
+  MOZ_COUNT_CTOR(SocketDeleteInstanceTask);
+}
+
+SocketDeleteInstanceTask::~SocketDeleteInstanceTask()
+{
+  MOZ_COUNT_DTOR(SocketDeleteInstanceTask);
+}
 
 void
 SocketDeleteInstanceTask::Run()
 {
   mIO = nullptr; // delete instance
 }
 
 //
 // SocketIOShutdownTask
 //
 
 SocketIOShutdownTask::SocketIOShutdownTask(SocketIOBase* aIO)
   : SocketIOTask<SocketIOBase>(aIO)
-{ }
+{
+  MOZ_COUNT_CTOR(SocketIOShutdownTask);
+}
+
+SocketIOShutdownTask::~SocketIOShutdownTask()
+{
+  MOZ_COUNT_DTOR(SocketIOShutdownTask);
+}
 
 void
 SocketIOShutdownTask::Run()
 {
   SocketIOBase* io = SocketIOTask<SocketIOBase>::GetIO();
 
   MOZ_ASSERT(!io->IsConsumerThread());
   MOZ_ASSERT(!io->IsShutdownOnIOThread());
--- a/ipc/unixsocket/SocketBase.h
+++ b/ipc/unixsocket/SocketBase.h
@@ -192,16 +192,17 @@ private:
  * |UnixSocketIOBuffer| is a |UnixSocketBuffer| that supports being
  * received on a socket or being send on a socket. Network protocols
  * might differ in their exact usage of Unix socket functions and
  * |UnixSocketIOBuffer| provides a protocol-neutral interface.
  */
 class UnixSocketIOBuffer : public UnixSocketBuffer
 {
 public:
+  UnixSocketIOBuffer();
   virtual ~UnixSocketIOBuffer();
 
   /**
    * Receives data from aFd at the end of the buffer. The returned value
    * is the number of newly received bytes, or 0 if the peer shut down
    * its connection, or a negative value on errors.
    */
   virtual ssize_t Receive(int aFd) = 0;
@@ -434,42 +435,45 @@ class SocketEventTask final : public Soc
 public:
   enum SocketEvent {
     CONNECT_SUCCESS,
     CONNECT_ERROR,
     DISCONNECT
   };
 
   SocketEventTask(SocketIOBase* aIO, SocketEvent aEvent);
+  ~SocketEventTask();
 
   void Run() override;
 
 private:
   SocketEvent mEvent;
 };
 
 /**
  * |SocketRequestClosingTask| closes an instance of |SocketBase|
  * on the consumer thread.
  */
 class SocketRequestClosingTask final : public SocketTask<SocketIOBase>
 {
 public:
   SocketRequestClosingTask(SocketIOBase* aIO);
+  ~SocketRequestClosingTask();
 
   void Run() override;
 };
 
 /**
  * |SocketDeleteInstanceTask| deletes an object on the consumer thread.
  */
 class SocketDeleteInstanceTask final : public Task
 {
 public:
   SocketDeleteInstanceTask(SocketIOBase* aIO);
+  ~SocketDeleteInstanceTask();
 
   void Run() override;
 
 private:
   nsAutoPtr<SocketIOBase> mIO;
 };
 
 //
@@ -515,16 +519,17 @@ private:
 /**
  * |SocketIOShutdownTask| signals shutdown to the socket I/O class on
  * the I/O thread and sends it to the consumer thread for destruction.
  */
 class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
 {
 public:
   SocketIOShutdownTask(SocketIOBase* aIO);
+  ~SocketIOShutdownTask();
 
   void Run() override;
 };
 
 }
 }
 
 #endif
--- a/ipc/unixsocket/StreamSocket.cpp
+++ b/ipc/unixsocket/StreamSocket.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "StreamSocket.h"
 #include <fcntl.h>
 #include "mozilla/RefPtr.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 #include "nsXULAppAPI.h"
 #include "StreamSocketConsumer.h"
 #include "UnixSocketConnector.h"
 
 static const size_t MAX_READ_SIZE = 1 << 16;
 
 namespace mozilla {
 namespace ipc {
@@ -96,16 +97,18 @@ StreamSocketIO::StreamSocketIO(MessageLo
                                StreamSocket* aStreamSocket,
                                UnixSocketConnector* aConnector)
   : ConnectionOrientedSocketIO(aConsumerLoop, aIOLoop, aConnector)
   , mStreamSocket(aStreamSocket)
   , mShuttingDownOnIOThread(false)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mStreamSocket);
+
+  MOZ_COUNT_CTOR_INHERITED(StreamSocketIO, ConnectionOrientedSocketIO);
 }
 
 StreamSocketIO::StreamSocketIO(MessageLoop* aConsumerLoop,
                                MessageLoop* aIOLoop,
                                int aFd, ConnectionStatus aConnectionStatus,
                                StreamSocket* aStreamSocket,
                                UnixSocketConnector* aConnector)
   : ConnectionOrientedSocketIO(aConsumerLoop,
@@ -113,22 +116,26 @@ StreamSocketIO::StreamSocketIO(MessageLo
                                aFd,
                                aConnectionStatus,
                                aConnector)
   , mStreamSocket(aStreamSocket)
   , mShuttingDownOnIOThread(false)
   , mDelayedConnectTask(nullptr)
 {
   MOZ_ASSERT(mStreamSocket);
+
+  MOZ_COUNT_CTOR_INHERITED(StreamSocketIO, ConnectionOrientedSocketIO);
 }
 
 StreamSocketIO::~StreamSocketIO()
 {
   MOZ_ASSERT(IsConsumerThread());
   MOZ_ASSERT(IsShutdownOnConsumerThread());
+
+  MOZ_COUNT_DTOR_INHERITED(StreamSocketIO, ConnectionOrientedSocketIO);
 }
 
 StreamSocket*
 StreamSocketIO::GetStreamSocket()
 {
   return mStreamSocket.get();
 }
 
@@ -187,17 +194,24 @@ StreamSocketIO::QueryReceiveBuffer(UnixS
  * to an instance of |StreamSocket| on the consumer thread.
  */
 class StreamSocketIO::ReceiveTask final : public SocketTask<StreamSocketIO>
 {
 public:
   ReceiveTask(StreamSocketIO* aIO, UnixSocketBuffer* aBuffer)
     : SocketTask<StreamSocketIO>(aIO)
     , mBuffer(aBuffer)
-  { }
+  {
+    MOZ_COUNT_CTOR(ReceiveTask);
+  }
+
+  ~ReceiveTask()
+  {
+    MOZ_COUNT_DTOR(ReceiveTask);
+  }
 
   void Run() override
   {
     StreamSocketIO* io = SocketTask<StreamSocketIO>::GetIO();
 
     MOZ_ASSERT(io->IsConsumerThread());
 
     if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
@@ -269,40 +283,53 @@ StreamSocketIO::ShutdownOnIOThread()
   Close(); // will also remove fd from I/O loop
   mShuttingDownOnIOThread = true;
 }
 
 //
 // Socket tasks
 //
 
-class StreamSocketIO::ConnectTask final
-  : public SocketIOTask<StreamSocketIO>
+class StreamSocketIO::ConnectTask final : public SocketIOTask<StreamSocketIO>
 {
 public:
   ConnectTask(StreamSocketIO* aIO)
-  : SocketIOTask<StreamSocketIO>(aIO)
-  { }
+    : SocketIOTask<StreamSocketIO>(aIO)
+  {
+    MOZ_COUNT_CTOR(ReceiveTask);
+  }
+
+  ~ConnectTask()
+  {
+    MOZ_COUNT_DTOR(ReceiveTask);
+  }
 
   void Run() override
   {
     MOZ_ASSERT(!GetIO()->IsConsumerThread());
     MOZ_ASSERT(!IsCanceled());
 
     GetIO()->Connect();
   }
 };
 
 class StreamSocketIO::DelayedConnectTask final
   : public SocketIOTask<StreamSocketIO>
 {
 public:
   DelayedConnectTask(StreamSocketIO* aIO)
     : SocketIOTask<StreamSocketIO>(aIO)
-  { }
+  {
+    MOZ_COUNT_CTOR(DelayedConnectTask);
+  }
+
+  ~DelayedConnectTask()
+  {
+    MOZ_COUNT_DTOR(DelayedConnectTask);
+  }
 
   void Run() override
   {
     MOZ_ASSERT(GetIO()->IsConsumerThread());
 
     if (IsCanceled()) {
       return;
     }
@@ -322,21 +349,25 @@ public:
 //
 
 StreamSocket::StreamSocket(StreamSocketConsumer* aConsumer, int aIndex)
   : mIO(nullptr)
   , mConsumer(aConsumer)
   , mIndex(aIndex)
 {
   MOZ_ASSERT(mConsumer);
+
+  MOZ_COUNT_CTOR_INHERITED(StreamSocket, ConnectionOrientedSocket);
 }
 
 StreamSocket::~StreamSocket()
 {
   MOZ_ASSERT(!mIO);
+
+  MOZ_COUNT_DTOR_INHERITED(StreamSocket, ConnectionOrientedSocket);
 }
 
 void
 StreamSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
 {
   mConsumer->ReceiveSocketData(mIndex, aBuffer);
 }
 
--- a/ipc/unixsocket/UnixSocketConnector.cpp
+++ b/ipc/unixsocket/UnixSocketConnector.cpp
@@ -1,19 +1,24 @@
 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "UnixSocketConnector.h"
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
 
 namespace mozilla {
 namespace ipc {
 
 UnixSocketConnector::UnixSocketConnector()
-{ }
+{
+  MOZ_COUNT_CTOR(UnixSocketConnector);
+}
 
 UnixSocketConnector::~UnixSocketConnector()
-{ }
+{
+  MOZ_COUNT_DTOR(UnixSocketConnector);
+}
 
 }
 }