Bug 1386601 - experimental patch to investigate Thunderbird topcrash, serializes S/MIME verification. rs=jorgk
authorKai Engert <kaie@kuix.de>
Tue, 15 Jan 2019 09:57:00 +0100
changeset 33355 279f3823f223
parent 33354 ee93a8e6c632
child 33356 4c0e476ae818
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1386601
Bug 1386601 - experimental patch to investigate Thunderbird topcrash, serializes S/MIME verification. rs=jorgk
mailnews/mime/src/nsCMS.cpp
--- a/mailnews/mime/src/nsCMS.cpp
+++ b/mailnews/mime/src/nsCMS.cpp
@@ -338,21 +338,33 @@ public:
                         unsigned char *aDigestData, uint32_t aDigestDataLen)
   {
     MOZ_ASSERT(NS_IsMainThread());
     mMessage = aMessage;
     mListener = aListener;
     mDigestData.Assign(reinterpret_cast<char *>(aDigestData), aDigestDataLen);
   }
 
+  static void InitStaticLock()
+  {
+    // If we ensure this is only executed on the main thread, we know
+    // there cannot be a race to allocate the lock multiple times.
+    MOZ_ASSERT(NS_IsMainThread());
+    if (!mLock) {
+      // Deliberate leak, one time allocation.
+      mLock = new mozilla::Mutex("SMimeVerificationTask");
+    }
+  }
+
 private:
   virtual nsresult CalculateResult() override
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
+    MutexAutoLock mon(*mLock);
     nsresult rv;
     if (!mDigestData.IsEmpty()) {
       rv = mMessage->VerifyDetachedSignature(
         reinterpret_cast<uint8_t*>(const_cast<char *>(mDigestData.get())),
         mDigestData.Length());
     } else {
       rv = mMessage->VerifySignature();
     }
@@ -365,21 +377,26 @@ private:
 
     nsCOMPtr<nsICMSMessage2> m2 = do_QueryInterface(mMessage);
     mListener->Notify(m2, rv);
   }
 
   nsCOMPtr<nsICMSMessage> mMessage;
   nsCOMPtr<nsISMimeVerificationListener> mListener;
   nsCString mDigestData;
+
+  static mozilla::Mutex *mLock;
 };
 
+mozilla::Mutex * SMimeVerificationTask::mLock = nullptr;
+
 nsresult nsCMSMessage::CommonAsyncVerifySignature(nsISMimeVerificationListener *aListener,
                                                   unsigned char* aDigestData, uint32_t aDigestDataLen)
 {
+  SMimeVerificationTask::InitStaticLock();
   RefPtr<CryptoTask> task = new SMimeVerificationTask(this, aListener, aDigestData, aDigestDataLen);
   return task->Dispatch("SMimeVerify");
 }
 
 class nsZeroTerminatedCertArray
 {
 public:
   nsZeroTerminatedCertArray()