Bug 1541114 - Check mIPCOpen before sending messages r=mayhemer
authorKershaw Chang <kershaw@mozilla.com>
Thu, 02 May 2019 12:00:57 +0000
changeset 531086 ee26da68184f8f32b402f3511c74ae96fac8e1f8
parent 531085 5a65215aac078d681a3be7709e2f6c76f523de7f
child 531087 f81b6439ae4e3a6cb7b9391fd894c5f9bbfc3bf3
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1541114
milestone68.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 1541114 - Check mIPCOpen before sending messages r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D27869
dom/network/TCPServerSocketParent.cpp
dom/network/TCPSocket.cpp
dom/network/TCPSocketParent.cpp
dom/network/TCPSocketParent.h
--- a/dom/network/TCPServerSocketParent.cpp
+++ b/dom/network/TCPServerSocketParent.cpp
@@ -47,18 +47,16 @@ TCPServerSocketParent::TCPServerSocketPa
 
 TCPServerSocketParent::~TCPServerSocketParent() {}
 
 void TCPServerSocketParent::Init() {
   NS_ENSURE_SUCCESS_VOID(mServerSocket->Init());
 }
 
 nsresult TCPServerSocketParent::SendCallbackAccept(TCPSocketParent* socket) {
-  socket->AddIPDLReference();
-
   nsresult rv;
 
   nsString host;
   rv = socket->GetHost(host);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to get host from nsITCPSocketParent");
     return NS_ERROR_FAILURE;
   }
@@ -67,16 +65,20 @@ nsresult TCPServerSocketParent::SendCall
   rv = socket->GetPort(&port);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to get port from nsITCPSocketParent");
     return NS_ERROR_FAILURE;
   }
 
   if (mNeckoParent) {
     if (mNeckoParent->SendPTCPSocketConstructor(socket, host, port)) {
+      // Call |AddIPDLReference| after the consructor message is sent
+      // successfully, otherwise |socket| could be leaked.
+      socket->AddIPDLReference();
+
       mozilla::Unused << PTCPServerSocketParent::SendCallbackAccept(socket);
     } else {
       NS_ERROR("Sending data from PTCPSocketParent was failed.");
     }
   } else {
     NS_ERROR("The member value for NeckoParent is wrong.");
   }
   return NS_OK;
--- a/dom/network/TCPSocket.cpp
+++ b/dom/network/TCPSocket.cpp
@@ -381,17 +381,17 @@ void TCPSocket::NotifyCopyComplete(nsres
     nsCOMPtr<nsIInputStream> stream = mPendingData[i];
     uint64_t available = 0;
     if (NS_SUCCEEDED(stream->Available(&available))) {
       bufferedAmount += available;
     }
   }
   mBufferedAmount = bufferedAmount;
 
-  if (mSocketBridgeParent) {
+  if (mSocketBridgeParent && mSocketBridgeParent->IPCOpen()) {
     mozilla::Unused << mSocketBridgeParent->SendUpdateBufferedAmount(
         BufferedAmount(), mTrackingNumber);
   }
 
   if (NS_FAILED(aStatus)) {
     MaybeReportErrorAndCloseIfOpen(aStatus);
     return;
   }
@@ -1001,16 +1001,18 @@ TCPSocket::OnStopRequest(nsIRequest* aRe
   }
 
   // We call this even if there is no error.
   MaybeReportErrorAndCloseIfOpen(aStatus);
   return NS_OK;
 }
 
 void TCPSocket::SetSocketBridgeParent(TCPSocketParent* aBridgeParent) {
+  MOZ_ASSERT(NS_IsMainThread());
+
   mSocketBridgeParent = aBridgeParent;
 }
 
 NS_IMETHODIMP
 TCPSocket::UpdateReadyState(uint32_t aReadyState) {
   MOZ_ASSERT(mSocketBridgeChild);
   mReadyState = static_cast<TCPReadyState>(aReadyState);
   return NS_OK;
--- a/dom/network/TCPSocketParent.cpp
+++ b/dom/network/TCPSocketParent.cpp
@@ -38,18 +38,20 @@ extern LazyLogModule gTCPSocketLog;
 #define TCPSOCKET_LOG(args) MOZ_LOG(gTCPSocketLog, LogLevel::Debug, args)
 #define TCPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gTCPSocketLog, LogLevel::Debug)
 }  // namespace net
 
 using namespace net;
 
 namespace dom {
 
-static void FireInteralError(mozilla::net::PTCPSocketParent* aActor,
+static void FireInteralError(TCPSocketParent* aActor,
                              uint32_t aLineNo) {
+  MOZ_ASSERT(aActor->IPCOpen());
+
   mozilla::Unused << aActor->SendCallback(
       NS_LITERAL_STRING("onerror"),
       TCPError(NS_LITERAL_STRING("InvalidStateError"),
                NS_LITERAL_STRING("Internal error")),
       static_cast<uint32_t>(TCPReadyState::Connecting));
 }
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPSocketParentBase)
--- a/dom/network/TCPSocketParent.h
+++ b/dom/network/TCPSocketParent.h
@@ -29,16 +29,18 @@ class TCPSocket;
 class TCPSocketParentBase : public nsISupports {
  public:
   NS_DECL_CYCLE_COLLECTION_CLASS(TCPSocketParentBase)
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
   void AddIPDLReference();
   void ReleaseIPDLReference();
 
+  bool IPCOpen() const { return mIPCOpen; }
+
  protected:
   TCPSocketParentBase();
   virtual ~TCPSocketParentBase();
 
   RefPtr<TCPSocket> mSocket;
   bool mIPCOpen;
 };