Bug 1193021 - clean up reference-counting in security/; r=keeler

This commit is contained in:
Nathan Froyd 2015-07-01 13:10:53 -04:00
Родитель 3b0a318c70
Коммит 8f318ea950
7 изменённых файлов: 28 добавлений и 54 удалений

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

@ -163,21 +163,13 @@ NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx,
++i, node = CERT_LIST_NEXT(node)) {
if (i == selectedIndex) {
nsNSSCertificate *cert = nsNSSCertificate::Create(node->cert);
nsRefPtr<nsNSSCertificate> cert = nsNSSCertificate::Create(node->cert);
if (!cert) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
nsIX509Cert *x509 = 0;
nsresult rv = cert->QueryInterface(NS_GET_IID(nsIX509Cert), (void**)&x509);
if (NS_FAILED(rv)) {
break;
}
NS_ADDREF(x509);
*_retval = x509;
NS_RELEASE(cert);
cert.forget(_retval);
break;
}
}

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

@ -196,12 +196,11 @@ CreateFromDER(unsigned char *data,
sequence->GetASN1Objects(getter_AddRefs(elements));
nsCOMPtr<nsIASN1Object> asn1Obj = do_QueryElementAt(elements, 0);
*retval = asn1Obj;
if (!*retval)
if (!asn1Obj) {
return NS_ERROR_FAILURE;
}
NS_ADDREF(*retval);
asn1Obj.forget(retval);
}
return rv;
}

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

@ -130,8 +130,7 @@ ProcessVersion(SECItem *versionItem,
if (NS_FAILED(rv))
return rv;
*retItem = printableItem;
NS_ADDREF(*retItem);
printableItem.forget(retItem);
return NS_OK;
}
@ -158,8 +157,7 @@ ProcessSerialNumberDER(SECItem *serialItem,
return NS_ERROR_OUT_OF_MEMORY;
rv = printableItem->SetDisplayValue(NS_ConvertASCIItoUTF16(serialNumber));
*retItem = printableItem;
NS_ADDREF(*retItem);
printableItem.forget(retItem);
return rv;
}
@ -1610,8 +1608,7 @@ ProcessSingleExtension(CERTCertExtension *extension,
text.Append(extvalue);
extensionItem->SetDisplayValue(text);
*retExtension = extensionItem;
NS_ADDREF(*retExtension);
extensionItem.forget(retExtension);
return NS_OK;
}
@ -1656,8 +1653,7 @@ ProcessSECAlgorithmID(SECAlgorithmID *algID,
}
printableItem->SetDisplayValue(text);
}
*retSequence = sequence;
NS_ADDREF(*retSequence);
sequence.forget(retSequence);
return NS_OK;
}
@ -2012,8 +2008,7 @@ nsNSSCertificate::CreateTBSCertificateASN1Struct(nsIASN1Sequence **retSequence,
if (NS_FAILED(rv))
return rv;
}
*retSequence = sequence;
NS_ADDREF(*retSequence);
sequence.forget(retSequence);
return NS_OK;
}

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

@ -787,8 +787,7 @@ nsNSSCertificate::GetIssuer(nsIX509Cert** aIssuer)
if (!cert) {
return NS_ERROR_UNEXPECTED;
}
*aIssuer = cert;
NS_ADDREF(*aIssuer);
cert.forget(aIssuer);
return NS_OK;
}
@ -1262,10 +1261,9 @@ nsNSSCertificate::GetValidity(nsIX509CertValidity** aValidity)
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_ARG(aValidity);
nsX509CertValidity* validity = new nsX509CertValidity(mCert.get());
nsRefPtr<nsX509CertValidity> validity = new nsX509CertValidity(mCert.get());
NS_ADDREF(validity);
*aValidity = static_cast<nsIX509CertValidity*>(validity);
validity.forget(aValidity);
return NS_OK;
}
@ -1723,8 +1721,7 @@ nsNSSCertList::GetEnumerator(nsISimpleEnumerator** _retval)
nsCOMPtr<nsISimpleEnumerator> enumerator =
new nsNSSCertListEnumerator(mCertList.get(), locker);
*_retval = enumerator;
NS_ADDREF(*_retval);
enumerator.forget(_retval);
return NS_OK;
}
@ -1853,8 +1850,7 @@ nsNSSCertListEnumerator::GetNext(nsISupports** _retval)
return NS_ERROR_OUT_OF_MEMORY;
}
*_retval = nssCert;
NS_ADDREF(*_retval);
nssCert.forget(_retval);
CERT_RemoveCertListNode(node);
return NS_OK;

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

@ -1385,12 +1385,11 @@ nsNSSCertificateDB::FindCertByEmailAddress(nsISupports *aToken, const char *aEma
}
// node now contains the first valid certificate with correct usage
nsNSSCertificate *nssCert = nsNSSCertificate::Create(node->cert);
nsRefPtr<nsNSSCertificate> nssCert = nsNSSCertificate::Create(node->cert);
if (!nssCert)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(nssCert);
*_retval = static_cast<nsIX509Cert*>(nssCert);
nssCert.forget(_retval);
return NS_OK;
}
@ -1695,8 +1694,7 @@ nsNSSCertificateDB::GetCerts(nsIX509CertList **_retval)
// (returns an empty list)
nssCertList = new nsNSSCertList(certList, locker);
*_retval = nssCertList;
NS_ADDREF(*_retval);
nssCertList.forget(_retval);
return NS_OK;
}

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

@ -424,8 +424,7 @@ NS_IMETHODIMP nsPK11TokenDB::GetInternalKeyToken(nsIPK11Token **_retval)
if (!slot) { rv = NS_ERROR_FAILURE; goto done; }
token = new nsPK11Token(slot);
*_retval = token;
NS_ADDREF(*_retval);
token.forget(_retval);
done:
if (slot) PK11_FreeSlot(slot);
@ -438,12 +437,13 @@ FindTokenByName(const char16_t* tokenName, nsIPK11Token **_retval)
nsNSSShutDownPreventionLock locker;
nsresult rv = NS_OK;
PK11SlotInfo *slot = 0;
nsCOMPtr<nsIPK11Token> token;
NS_ConvertUTF16toUTF8 aUtf8TokenName(tokenName);
slot = PK11_FindSlotByName(const_cast<char*>(aUtf8TokenName.get()));
if (!slot) { rv = NS_ERROR_FAILURE; goto done; }
*_retval = new nsPK11Token(slot);
NS_ADDREF(*_retval);
token = new nsPK11Token(slot);
token.forget(_retval);
done:
if (slot) PK11_FreeSlot(slot);

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

@ -169,8 +169,7 @@ nsPKCS11Slot::GetToken(nsIPK11Token **_retval)
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsIPK11Token> token = new nsPK11Token(mSlot);
*_retval = token;
NS_ADDREF(*_retval);
token.forget(_retval);
return NS_OK;
}
@ -319,8 +318,7 @@ nsPKCS11Module::FindSlotByName(const char16_t *aName,
free(asciiname);
nsCOMPtr<nsIPKCS11Slot> slot = new nsPKCS11Slot(slotinfo);
PK11_FreeSlot(slotinfo);
*_retval = slot;
NS_ADDREF(*_retval);
slot.forget(_retval);
return NS_OK;
}
@ -372,8 +370,7 @@ nsPKCS11ModuleDB::GetInternal(nsIPKCS11Module **_retval)
SECMOD_CreateModule(nullptr, SECMOD_INT_NAME, nullptr, SECMOD_INT_FLAGS);
nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod);
SECMOD_DestroyModule(nssMod);
*_retval = module;
NS_ADDREF(*_retval);
module.forget(_retval);
return NS_OK;
}
@ -385,8 +382,7 @@ nsPKCS11ModuleDB::GetInternalFIPS(nsIPKCS11Module **_retval)
SECMOD_CreateModule(nullptr, SECMOD_FIPS_NAME, nullptr, SECMOD_FIPS_FLAGS);
nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(nssMod);
SECMOD_DestroyModule(nssMod);
*_retval = module;
NS_ADDREF(*_retval);
module.forget(_retval);
return NS_OK;
}
@ -402,8 +398,7 @@ nsPKCS11ModuleDB::FindModuleByName(const char16_t *aName,
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPKCS11Module> module = new nsPKCS11Module(mod);
SECMOD_DestroyModule(mod);
*_retval = module;
NS_ADDREF(*_retval);
module.forget(_retval);
return NS_OK;
}
@ -422,8 +417,7 @@ nsPKCS11ModuleDB::FindSlotByName(const char16_t *aName,
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPKCS11Slot> slot = new nsPKCS11Slot(slotinfo);
PK11_FreeSlot(slotinfo);
*_retval = slot;
NS_ADDREF(*_retval);
slot.forget(_retval);
return NS_OK;
}