Fix valgrind warning about writing uninitialized memory to disk cache by not allocating extra size for disk cache entries and then writing the extra word. b=368119 r+sr=darin
git-svn-id: svn://10.0.0.236/trunk@218930 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
d939edf204
commit
7cb106739c
2
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
2
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
@ -53,7 +53,7 @@
|
||||
class nsDiskCache {
|
||||
public:
|
||||
enum {
|
||||
kCurrentVersion = 0x0001000A // format = 16 bits major version/16 bits minor version
|
||||
kCurrentVersion = 0x0001000B // format = 16 bits major version/16 bits minor version
|
||||
};
|
||||
|
||||
enum { kData, kMetaData };
|
||||
|
||||
@ -130,8 +130,8 @@ nsDiskCacheEvictor::VisitRecord(nsDiskCacheRecord * mapRecord)
|
||||
|
||||
// Compare clientID's without malloc
|
||||
if ((diskEntry->mKeySize <= mClientIDSize) ||
|
||||
(diskEntry->mKeyStart[mClientIDSize] != ':') ||
|
||||
(memcmp(diskEntry->mKeyStart, mClientID, mClientIDSize) != 0)) {
|
||||
(diskEntry->Key()[mClientIDSize] != ':') ||
|
||||
(memcmp(diskEntry->Key(), mClientID, mClientIDSize) != 0)) {
|
||||
delete [] (char *)diskEntry;
|
||||
return kVisitNextRecord; // clientID doesn't match, skip it
|
||||
}
|
||||
@ -422,7 +422,7 @@ nsDiskCacheDevice::FindEntry(nsCString * key, PRBool *collision)
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
|
||||
// compare key to be sure
|
||||
if (strcmp(diskEntry->mKeyStart, key->get()) == 0) {
|
||||
if (strcmp(diskEntry->Key(), key->get()) == 0) {
|
||||
entry = diskEntry->CreateCacheEntry(this);
|
||||
} else {
|
||||
*collision = PR_TRUE;
|
||||
|
||||
12
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
12
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
@ -60,7 +60,7 @@ nsCacheEntry *
|
||||
nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
|
||||
{
|
||||
nsCacheEntry * entry = nsnull;
|
||||
nsresult rv = nsCacheEntry::Create(mKeyStart,
|
||||
nsresult rv = nsCacheEntry::Create(Key(),
|
||||
nsICache::STREAM_BASED,
|
||||
nsICache::STORE_ON_DISK,
|
||||
device,
|
||||
@ -75,7 +75,7 @@ nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
|
||||
// XXX why does nsCacheService have to fill out device in BindEntry()?
|
||||
entry->SetDataSize(mDataSize);
|
||||
|
||||
rv = entry->UnflattenMetaData(&mKeyStart[mKeySize], mMetaDataSize);
|
||||
rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete entry;
|
||||
return nsnull;
|
||||
@ -115,9 +115,9 @@ CreateDiskCacheEntry(nsDiskCacheBinding * binding,
|
||||
diskEntry->mKeySize = keySize;
|
||||
diskEntry->mMetaDataSize = metaSize;
|
||||
|
||||
memcpy(diskEntry->mKeyStart, entry->Key()->get(),keySize);
|
||||
memcpy(diskEntry->Key(), entry->Key()->get(),keySize);
|
||||
|
||||
nsresult rv = entry->FlattenMetaData(&diskEntry->mKeyStart[keySize], metaSize);
|
||||
nsresult rv = entry->FlattenMetaData(diskEntry->MetaData(), metaSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete [] (char *)diskEntry;
|
||||
return nsnull;
|
||||
@ -136,7 +136,7 @@ NS_IMPL_ISUPPORTS1(nsDiskCacheEntryInfo, nsICacheEntryInfo)
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientID);
|
||||
return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->mKeyStart), clientID);
|
||||
return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID);
|
||||
}
|
||||
|
||||
extern const char DISK_CACHE_DEVICE_ID[];
|
||||
@ -150,7 +150,7 @@ NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
|
||||
{
|
||||
return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->mKeyStart), clientKey);
|
||||
return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(PRInt32 *aFetchCount)
|
||||
|
||||
15
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
15
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
@ -60,13 +60,20 @@ struct nsDiskCacheEntry {
|
||||
PRUint32 mDataSize;
|
||||
PRUint32 mKeySize; // includes terminating null byte
|
||||
PRUint32 mMetaDataSize; // includes terminating null byte
|
||||
char mKeyStart[1]; // start of key data
|
||||
// mMetaDataStart = mKeyStart[mKeySize];
|
||||
// followed by key data (mKeySize bytes)
|
||||
// followed by meta data (mMetaDataSize bytes)
|
||||
|
||||
PRUint32 Size() { return offsetof(nsDiskCacheEntry,mKeyStart) +
|
||||
PRUint32 Size() { return sizeof(nsDiskCacheEntry) +
|
||||
mKeySize + mMetaDataSize;
|
||||
}
|
||||
|
||||
char* Key() { return NS_REINTERPRET_CAST(char*const, this) +
|
||||
sizeof(nsDiskCacheEntry);
|
||||
}
|
||||
|
||||
char* MetaData()
|
||||
{ return Key() + mKeySize; }
|
||||
|
||||
nsCacheEntry * CreateCacheEntry(nsCacheDevice * device);
|
||||
|
||||
void Swap() // host to network (memory to disk)
|
||||
@ -121,7 +128,7 @@ public:
|
||||
|
||||
virtual ~nsDiskCacheEntryInfo() {}
|
||||
|
||||
const char* Key() { return mDiskEntry->mKeyStart; }
|
||||
const char* Key() { return mDiskEntry->Key(); }
|
||||
|
||||
private:
|
||||
const char * mDeviceID;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user