diff --git a/security/manager/ssl/src/nsNSSComponent.cpp b/security/manager/ssl/src/nsNSSComponent.cpp index 768e58792a0d..167a4c007cc3 100644 --- a/security/manager/ssl/src/nsNSSComponent.cpp +++ b/security/manager/ssl/src/nsNSSComponent.cpp @@ -1605,15 +1605,18 @@ PSMContentDownloader::OnStartRequest(nsIRequest* request, nsISupports* context) // Get the URI // channel->GetURI(getter_AddRefs(mURI)); - rv = channel->GetContentLength(&mContentLength); - if (rv != NS_OK || mContentLength == -1) - mContentLength = kDefaultCertAllocLength; + PRInt32 contentLength; + rv = channel->GetContentLength(&contentLength); + if (NS_FAILED(rv) || contentLength <= 0) + contentLength = kDefaultCertAllocLength; mBufferOffset = 0; - mByteData = (char*) nsMemory::Alloc(mContentLength); + mBufferSize = 0; + mByteData = (char*) nsMemory::Alloc(contentLength); if (!mByteData) return NS_ERROR_OUT_OF_MEMORY; + mBufferSize = contentLength; return NS_OK; } @@ -1630,21 +1633,21 @@ PSMContentDownloader::OnDataAvailable(nsIRequest* request, PRUint32 amt; nsresult err; //Do a check to see if we need to allocate more memory. - if ((mBufferOffset + (PRInt32)aLength) > mContentLength) { - size_t newSize = mContentLength + kDefaultCertAllocLength; + if ((mBufferOffset + (PRInt32)aLength) > mBufferSize) { + size_t newSize = (mBufferOffset + aLength) *2; // grow some more than needed char *newBuffer; newBuffer = (char*)nsMemory::Realloc(mByteData, newSize); if (newBuffer == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } mByteData = newBuffer; - mContentLength = newSize; + mBufferSize = newSize; } PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("CertDownloader::OnDataAvailable\n")); do { err = aIStream->Read(mByteData+mBufferOffset, - mContentLength-mBufferOffset, &amt); + aLength, &amt); if (amt == 0) break; if (NS_FAILED(err)) return err; diff --git a/security/manager/ssl/src/nsNSSComponent.h b/security/manager/ssl/src/nsNSSComponent.h index b6364bb81484..db2a82b74d5b 100644 --- a/security/manager/ssl/src/nsNSSComponent.h +++ b/security/manager/ssl/src/nsNSSComponent.h @@ -88,7 +88,7 @@ public: protected: char* mByteData; PRInt32 mBufferOffset; - PRInt32 mContentLength; + PRInt32 mBufferSize; PRUint32 mType; PRBool mDoSilentDownload; nsAutoString mCrlAutoDownloadKey;