From 99fe8f3daf94f66ac450a29ff717d21415a6124c Mon Sep 17 00:00:00 2001 From: "gordon%netscape.com" Date: Fri, 10 May 2002 23:44:53 +0000 Subject: [PATCH] fix for bug 91795 "large downloads cause mozilla to consume too much memory". Changed OnDataSizeChange() to abort when entry size exceeds cache capacity. r=dougt, sr=darin. --- netwerk/cache/src/nsDiskCacheDevice.cpp | 9 ++++++++- netwerk/cache/src/nsMemoryCacheDevice.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/netwerk/cache/src/nsDiskCacheDevice.cpp b/netwerk/cache/src/nsDiskCacheDevice.cpp index 6e7fdd1b6f0..2dff6f16956 100644 --- a/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -631,8 +631,15 @@ nsDiskCacheDevice::OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize) NS_ASSERTION(binding->mRecord.ValidRecord(), "bad record"); + PRUint32 newSize = entry->DataSize() + deltaSize; + if (newSize > mCacheCapacity) { + nsresult rv = nsCacheService::GlobalInstance()->DoomEntry_Locked(entry); + NS_ASSERTION(NS_SUCCEEDED(rv),"DoomEntry_Locked() failed."); + return NS_ERROR_ABORT; + } + PRUint32 sizeK = ((entry->DataSize() + 0x0399) >> 10); // round up to next 1k - PRUint32 newSizeK = ((entry->DataSize() + deltaSize + 0x399) >> 10); + PRUint32 newSizeK = ((newSize + 0x399) >> 10); NS_ASSERTION((sizeK < USHRT_MAX) && (sizeK == binding->mRecord.DataFileSize()), "data size out of sync"); diff --git a/netwerk/cache/src/nsMemoryCacheDevice.cpp b/netwerk/cache/src/nsMemoryCacheDevice.cpp index 4eb9d39889a..0e0c8cf7a16 100644 --- a/netwerk/cache/src/nsMemoryCacheDevice.cpp +++ b/netwerk/cache/src/nsMemoryCacheDevice.cpp @@ -250,6 +250,12 @@ nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize) { if (entry->IsStreamData()) { // we have the right to refuse or pre-evict + PRUint32 newSize = entry->DataSize() + deltaSize; + if (newSize > mSoftLimit) { + nsresult rv = nsCacheService::GlobalInstance()->DoomEntry_Locked(entry); + NS_ASSERTION(NS_SUCCEEDED(rv),"DoomEntry_Locked() failed."); + return NS_ERROR_ABORT; + } } // adjust our totals