Bug 959485, part 1 - Remove null checks of the result of new nsJS*ID. r=gabor

This commit is contained in:
Andrew McCreight 2014-01-16 08:49:25 -08:00
parent 57b34ac824
commit b6a2f503ca

View File

@ -173,11 +173,9 @@ nsJSID::NewID(const char* str)
} }
nsJSID* idObj = new nsJSID(); nsJSID* idObj = new nsJSID();
if (idObj) { NS_ADDREF(idObj);
NS_ADDREF(idObj); if (NS_FAILED(idObj->Initialize(str)))
if (NS_FAILED(idObj->Initialize(str))) NS_RELEASE(idObj);
NS_RELEASE(idObj);
}
return idObj; return idObj;
} }
@ -186,12 +184,10 @@ nsJSID*
nsJSID::NewID(const nsID& id) nsJSID::NewID(const nsID& id)
{ {
nsJSID* idObj = new nsJSID(); nsJSID* idObj = new nsJSID();
if (idObj) { NS_ADDREF(idObj);
NS_ADDREF(idObj); idObj->mID = id;
idObj->mID = id; idObj->mName = nullptr;
idObj->mName = nullptr; idObj->mNumber = nullptr;
idObj->mNumber = nullptr;
}
return idObj; return idObj;
} }
@ -625,27 +621,25 @@ nsJSCID::NewID(const char* str)
} }
nsJSCID* idObj = new nsJSCID(); nsJSCID* idObj = new nsJSCID();
if (idObj) { bool success = false;
bool success = false; NS_ADDREF(idObj);
NS_ADDREF(idObj);
if (str[0] == '{') { if (str[0] == '{') {
if (NS_SUCCEEDED(idObj->Initialize(str))) if (NS_SUCCEEDED(idObj->Initialize(str)))
success = true; success = true;
} else { } else {
nsCOMPtr<nsIComponentRegistrar> registrar; nsCOMPtr<nsIComponentRegistrar> registrar;
NS_GetComponentRegistrar(getter_AddRefs(registrar)); NS_GetComponentRegistrar(getter_AddRefs(registrar));
if (registrar) { if (registrar) {
nsCID *cid; nsCID *cid;
if (NS_SUCCEEDED(registrar->ContractIDToCID(str, &cid))) { if (NS_SUCCEEDED(registrar->ContractIDToCID(str, &cid))) {
success = idObj->mDetails.InitWithName(*cid, str); success = idObj->mDetails.InitWithName(*cid, str);
nsMemory::Free(cid); nsMemory::Free(cid);
}
} }
} }
if (!success)
NS_RELEASE(idObj);
} }
if (!success)
NS_RELEASE(idObj);
return idObj; return idObj;
} }