Bug 1232454 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in security/apps/; r=keeler

As a nice side effect, we also fix a (rare) memory leak in
AppTrustDomain::SetTrustedRoot.
This commit is contained in:
Nathan Froyd 2015-12-06 08:06:03 -05:00
Родитель c04bec08b0
Коммит 2c2f66f499
2 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -46,7 +46,7 @@ static char kDevImportedDER[] =
namespace mozilla { namespace psm {
StaticMutex AppTrustDomain::sMutex;
nsAutoArrayPtr<unsigned char> AppTrustDomain::sDevImportedDERData(nullptr);
UniquePtr<unsigned char[]> AppTrustDomain::sDevImportedDERData;
unsigned int AppTrustDomain::sDevImportedDERLen = 0;
AppTrustDomain::AppTrustDomain(ScopedCERTCertList& certChain, void* pinArg)
@ -144,18 +144,18 @@ AppTrustDomain::SetTrustedRoot(AppTrustedRoot trustedRoot)
return SECFailure;
}
char* data = new char[length];
rv = inputStream->Read(data, length, &sDevImportedDERLen);
auto data = MakeUnique<char[]>(length);
rv = inputStream->Read(data.get(), length, &sDevImportedDERLen);
if (NS_FAILED(rv)) {
PR_SetError(SEC_ERROR_IO, 0);
return SECFailure;
}
MOZ_ASSERT(length == sDevImportedDERLen);
sDevImportedDERData = reinterpret_cast<unsigned char*>(data);
sDevImportedDERData.reset(reinterpret_cast<unsigned char*>(data.release()));
}
trustedDER.data = sDevImportedDERData;
trustedDER.data = sDevImportedDERData.get();
trustedDER.len = sDevImportedDERLen;
break;
}

Просмотреть файл

@ -9,7 +9,7 @@
#include "pkix/pkixtypes.h"
#include "mozilla/StaticMutex.h"
#include "nsAutoPtr.h"
#include "mozilla/UniquePtr.h"
#include "nsDebug.h"
#include "nsIX509CertDB.h"
#include "ScopedNSSTypes.h"
@ -73,7 +73,7 @@ private:
unsigned int mMinRSABits;
static StaticMutex sMutex;
static nsAutoArrayPtr<unsigned char> sDevImportedDERData;
static UniquePtr<unsigned char[]> sDevImportedDERData;
static unsigned int sDevImportedDERLen;
};