From 2b2d8447b83112a01dd61c2979b683a699d3d775 Mon Sep 17 00:00:00 2001 From: "rvargas@google.com" Date: Fri, 19 Dec 2008 22:35:47 +0000 Subject: Use appropriate version of delete in storage block depending on how storage was allocated. B=5041 Review URL: http://codereview.chromium.org/15032/show git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7324 0039d316-1c4b-4281-b951-d872f2087c98 --- net/disk_cache/storage_block-inl.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'net/disk_cache/storage_block-inl.h') diff --git a/net/disk_cache/storage_block-inl.h b/net/disk_cache/storage_block-inl.h index 890954e..2082b0a 100644 --- a/net/disk_cache/storage_block-inl.h +++ b/net/disk_cache/storage_block-inl.h @@ -23,8 +23,7 @@ template StorageBlock::StorageBlock(MappedFile* file, template StorageBlock::~StorageBlock() { if (modified_) Store(); - if (own_data_) - delete data_; + DeleteData(); } template void* StorageBlock::buffer() const { @@ -58,10 +57,7 @@ template bool StorageBlock::LazyInit(MappedFile* file, template void StorageBlock::SetData(T* other) { DCHECK(!modified_); - if (own_data_) { - delete data_; - own_data_ = false; - } + DeleteData(); data_ = other; } @@ -122,6 +118,18 @@ template void StorageBlock::AllocateData() { own_data_ = true; } +template void StorageBlock::DeleteData() { + if (own_data_) { + if (!extended_) { + delete data_; + } else { + data_->~T(); + delete[] reinterpret_cast(data_); + } + own_data_ = false; + } +} + } // namespace disk_cache #endif // NET_DISK_CACHE_CACHE_INTERNAL_INL_H__ -- cgit v1.1