Skip to content

Commit

Permalink
bug 1444532 - fix a leak in SHA256 in nsHttpConnectionInfo.cpp r=mayh…
Browse files Browse the repository at this point in the history
…emer

The original code (from bug 1200802) declared an XPCOM object as a static bare
pointer, which for future reference is probably never the right thing to do. It
might have worked if it was cleared before shutdown but it never was.

MozReview-Commit-ID: EMe7wgzm6zv
  • Loading branch information
mozkeeler committed Mar 9, 2018
1 parent 5d5a26d commit 473a29f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions netwerk/protocol/http/nsHttpConnectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,29 @@
#define LOG_ENABLED() LOG5_ENABLED()

#include "nsHttpConnectionInfo.h"

#include "mozilla/net/DNS.h"
#include "prnetdb.h"
#include "nsICryptoHash.h"
#include "nsComponentManagerUtils.h"
#include "nsICryptoHash.h"
#include "nsIProtocolProxyService.h"
#include "nsNetCID.h"
#include "prnetdb.h"

static nsresult
SHA256(const char* aPlainText, nsAutoCString& aResult)
{
static nsICryptoHash* hasher = nullptr;
nsresult rv;
if (!hasher) {
rv = CallCreateInstance("@mozilla.org/security/hash;1", &hasher);
nsresult rv;
nsCOMPtr<nsICryptoHash> hasher =
do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
LOG(("nsHttpDigestAuth: no crypto hash!\n"));
return rv;
}
}

rv = hasher->Init(nsICryptoHash::SHA256);
NS_ENSURE_SUCCESS(rv, rv);

rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText));
NS_ENSURE_SUCCESS(rv, rv);

rv = hasher->Finish(false, aResult);
return rv;
rv = hasher->Init(nsICryptoHash::SHA256);
NS_ENSURE_SUCCESS(rv, rv);
rv = hasher->Update((unsigned char*) aPlainText, strlen(aPlainText));
NS_ENSURE_SUCCESS(rv, rv);
return hasher->Finish(false, aResult);
}

namespace mozilla {
Expand Down

0 comments on commit 473a29f

Please sign in to comment.