Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth managers, r=shuang
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 29 Feb 2016 12:15:08 +0100
changeset 322406 b89196c9ac0887763309929a64c45117edef6fd9
parent 322405 164b34c28be4c5415b9a5c8e09a1c422cabed902
child 322407 0270da6c994915bbc5a0919e6f3377f415674b76
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang
bugs1251541
milestone47.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 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth managers, r=shuang
dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
dom/bluetooth/bluedroid/BluetoothOppManager.cpp
dom/bluetooth/bluedroid/BluetoothOppManager.h
dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
dom/bluetooth/bluez/BluetoothOppManager.cpp
dom/bluetooth/bluez/BluetoothOppManager.h
dom/bluetooth/common/ObexBase.h
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.cpp
@@ -1439,17 +1439,17 @@ BluetoothMapSmsManager::HandleSmsMmsPush
    *
    * We only support UTF-8 charset due to current SMS API limitation.
    */
   AppendBtNamedValueByTagId(aHeader, data, Map::AppParametersTagId::Charset);
 
   // Get Body
   uint8_t* bodyPtr = nullptr;
   aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-  mBodySegment = bodyPtr;
+  mBodySegment.reset(bodyPtr);
 
   RefPtr<BluetoothMapBMessage> bmsg =
     new BluetoothMapBMessage(bodyPtr, mBodySegmentLength);
 
   /* If FolderName is outbox:
    *   1. Parse body to get SMS
    *   2. Get receipent subject
    *   3. Send it to Gaia
--- a/dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothMapSmsManager.h
@@ -280,17 +280,17 @@ private:
   // over the ownership to mMasSocket, and get a new server socket while Listen()
   // is called.
   RefPtr<BluetoothSocket> mMasServerSocket;
 
   // Message notification service client socket
   RefPtr<BluetoothSocket> mMnsSocket;
 
   int mBodySegmentLength;
-  nsAutoArrayPtr<uint8_t> mBodySegment;
+  UniquePtr<uint8_t[]> mBodySegment;
 
   /**
    * The bMessage/message-listing data stream for current processing response
    */
   nsCOMPtr<nsIInputStream> mDataStream;
 };
 
 END_BLUETOOTH_NAMESPACE
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp
@@ -798,17 +798,17 @@ BluetoothOppManager::ExtractPacketHeader
   if (aHeader.Has(ObexHeaderId::Length)) {
     aHeader.GetLength(&mFileLength);
   }
 
   if (aHeader.Has(ObexHeaderId::Body) ||
       aHeader.Has(ObexHeaderId::EndOfBody)) {
     uint8_t* bodyPtr;
     aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-    mBodySegment = bodyPtr;
+    mBodySegment.reset(bodyPtr);
   }
 }
 
 bool
 BluetoothOppManager::ExtractBlobHeaders()
 {
   RetrieveSentFileName();
   mBlob->GetType(mContentType);
@@ -929,17 +929,17 @@ BluetoothOppManager::ComposePacket(uint8
     mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
 
     /**
      * A PUT request from remote devices may be divided into multiple parts.
      * In other words, one request may need to be received multiple times,
      * so here we keep a variable mPutPacketReceivedLength to indicate if
      * current PUT request is done.
      */
-    mReceivedDataBuffer = new uint8_t[mPacketLength];
+    mReceivedDataBuffer.reset(new uint8_t[mPacketLength]);
     mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
   }
 
   int dataLength = aMessage->GetSize() - frameHeaderLength;
 
   // Check length before memcpy to prevent from memory pollution
   if (dataLength < 0 ||
       mPutPacketReceivedLength + dataLength > mPacketLength) {
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.h
+++ b/dom/bluetooth/bluedroid/BluetoothOppManager.h
@@ -202,18 +202,18 @@ private:
   bool mWaitingForConfirmationFlag;
 
   nsString mFileName;
   nsString mContentType;
   uint32_t mFileLength;
   uint32_t mSentFileLength;
   bool mWaitingToSendPutFinal;
 
-  nsAutoArrayPtr<uint8_t> mBodySegment;
-  nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
+  UniquePtr<uint8_t[]> mBodySegment;
+  UniquePtr<uint8_t[]> mReceivedDataBuffer;
 
   int mCurrentBlobIndex;
   RefPtr<Blob> mBlob;
   nsTArray<SendFileBatch> mBatches;
 
   /**
    * A seperate member thread is required because our read calls can block
    * execution, which is not allowed to happen on the IOThread.
--- a/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp
@@ -790,24 +790,24 @@ BluetoothPbapManager::ReplyToConnect(con
   index += AppendHeaderConnectionId(&res[index], 0x01);
 
   // Authentication response
   if (!aPassword.IsEmpty()) {
     // Section 3.5.2.1 "Request-digest", PBAP 1.2
     // The request-digest is required and calculated as follows:
     //   H(nonce ":" password)
     uint32_t hashStringLength = DIGEST_LENGTH + aPassword.Length() + 1;
-    nsAutoArrayPtr<char> hashString(new char[hashStringLength]);
+    UniquePtr<char[]> hashString(new char[hashStringLength]);
 
-    memcpy(hashString, mRemoteNonce, DIGEST_LENGTH);
+    memcpy(hashString.get(), mRemoteNonce, DIGEST_LENGTH);
     hashString[DIGEST_LENGTH] = ':';
     memcpy(&hashString[DIGEST_LENGTH + 1],
            NS_ConvertUTF16toUTF8(aPassword).get(),
            aPassword.Length());
-    MD5Hash(hashString, hashStringLength);
+    MD5Hash(hashString.get(), hashStringLength);
 
     // 2 tag-length-value triplets: <request-digest:16><nonce:16>
     uint8_t digestResponse[(DIGEST_LENGTH + 2) * 2];
     int offset = AppendAppParameter(digestResponse, sizeof(digestResponse),
                                     ObexDigestResponse::ReqDigest,
                                     mHashRes, DIGEST_LENGTH);
     offset += AppendAppParameter(&digestResponse[offset],
                                  sizeof(digestResponse) - offset,
@@ -1085,18 +1085,18 @@ BluetoothPbapManager::ReplyToGet(uint16_
       opcode = ObexResponseCode::Success;
     } else {
       // Compute remaining packet size to append Body, excluding Body's header
       uint32_t remainingPacketSize =
         mRemoteMaxPacketLength - kObexBodyHeaderSize - index;
 
       // Read vCard data from input stream
       uint32_t numRead = 0;
-      nsAutoArrayPtr<char> buf(new char[remainingPacketSize]);
-      rv = mVCardDataStream->Read(buf, remainingPacketSize, &numRead);
+      UniquePtr<char[]> buf(new char[remainingPacketSize]);
+      rv = mVCardDataStream->Read(buf.get(), remainingPacketSize, &numRead);
       if (NS_FAILED(rv)) {
         BT_LOGR("Failed to read from input stream. rv=0x%x",
                 static_cast<uint32_t>(rv));
         return false;
       }
 
       // |numRead| must be non-zero as |bytesAvailable| is non-zero
       MOZ_ASSERT(numRead);
--- a/dom/bluetooth/bluez/BluetoothOppManager.cpp
+++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp
@@ -716,17 +716,17 @@ BluetoothOppManager::ExtractPacketHeader
   if (aHeader.Has(ObexHeaderId::Length)) {
     aHeader.GetLength(&mFileLength);
   }
 
   if (aHeader.Has(ObexHeaderId::Body) ||
       aHeader.Has(ObexHeaderId::EndOfBody)) {
     uint8_t* bodyPtr;
     aHeader.GetBody(&bodyPtr, &mBodySegmentLength);
-    mBodySegment = bodyPtr;
+    mBodySegment.reset(bodyPtr);
   }
 }
 
 bool
 BluetoothOppManager::ExtractBlobHeaders()
 {
   RetrieveSentFileName();
   mBlob->GetType(mContentType);
@@ -846,17 +846,17 @@ BluetoothOppManager::ComposePacket(uint8
 
     mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
     /**
      * A PUT request from remote devices may be divided into multiple parts.
      * In other words, one request may need to be received multiple times,
      * so here we keep a variable mPutPacketReceivedLength to indicate if
      * current PUT request is done.
      */
-    mReceivedDataBuffer = new uint8_t[mPacketLength];
+    mReceivedDataBuffer.reset(new uint8_t[mPacketLength]);
     mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal);
   }
 
   int dataLength = aMessage->GetSize() - frameHeaderLength;
 
   // Check length before memcpy to prevent from memory pollution
   if (dataLength < 0 ||
       mPutPacketReceivedLength + dataLength > mPacketLength) {
--- a/dom/bluetooth/bluez/BluetoothOppManager.h
+++ b/dom/bluetooth/bluez/BluetoothOppManager.h
@@ -186,18 +186,18 @@ private:
   bool mWaitingForConfirmationFlag;
 
   nsString mFileName;
   nsString mContentType;
   uint32_t mFileLength;
   uint32_t mSentFileLength;
   bool mWaitingToSendPutFinal;
 
-  nsAutoArrayPtr<uint8_t> mBodySegment;
-  nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
+  UniquePtr<uint8_t[]> mBodySegment;
+  UniquePtr<uint8_t[]> mReceivedDataBuffer;
 
   int mCurrentBlobIndex;
   RefPtr<Blob> mBlob;
   nsTArray<SendFileBatch> mBatches;
 
   /**
    * A seperate member thread is required because our read calls can block
    * execution, which is not allowed to happen on the IOThread.
--- a/dom/bluetooth/common/ObexBase.h
+++ b/dom/bluetooth/common/ObexBase.h
@@ -139,27 +139,27 @@ enum ObexDigestResponse {
 class ObexHeader
 {
 public:
   ObexHeader(ObexHeaderId aId, int aDataLength, const uint8_t* aData)
     : mId(aId)
     , mDataLength(aDataLength)
     , mData(nullptr)
   {
-    mData = new uint8_t[mDataLength];
-    memcpy(mData, aData, aDataLength);
+    mData.reset(new uint8_t[mDataLength]);
+    memcpy(mData.get(), aData, aDataLength);
   }
 
   ~ObexHeader()
   {
   }
 
   ObexHeaderId mId;
   int mDataLength;
-  nsAutoArrayPtr<uint8_t> mData;
+  UniquePtr<uint8_t[]> mData;
 };
 
 class ObexHeaderSet
 {
 public:
   ObexHeaderSet()
   {
   }