Status: Untriaged Owner: [EMAIL PROTECTED] CC: [EMAIL PROTECTED], [EMAIL PROTECTED] Labels: Type-Bug Pri-2 OS-All Area-Misc
New issue 5041 by [EMAIL PROTECTED]: Valgrind error in disk cache backend http://code.google.com/p/chromium/issues/detail?id=5041 The follow error is a bit iffy (the code will operate fine), however, the error has a point and I think we should fix it. I have annotated the code a bit below to explain what's happening: template<typename T> void StorageBlock<T>::AllocateData() { ... void* buffer = new char[address_.num_blocks() * sizeof(*data_)]; // We use placement new to call the constructor for T with // |this| as the buffer we just allocated with new[]. data_ = new(buffer) T; } own_data_ = true; } template<typename T> StorageBlock<T>::~StorageBlock() { if (modified_) Store(); if (own_data_) delete data_; } We call delete data_, which will cause the destructor for T to be called, but then also to free the memory. This is a mismatch in new[] and delete. It is ok in this case since we allocated a char and there are no destructors that need to be run. However, I think it would still be cleaner to: Explicitly call T::~T, since this matches our placement new initialization Call delete[] on reinterpret_cast<char*>(data_), or some other approach to make sure the allocation of |buffer| matches how it's freed. ==25173== Thread 2: ==25173== Mismatched free() / delete / delete [] ==25173== at 0x75E76C9: operator delete(void*) (vg_replace_malloc.c:342) ==25173== by 0x81C939A: disk_cache::StorageBlock<disk_cache::EntryStore>::~StorageBlock() (storage_block-inl.h:27) ==25173== by 0x81C789A: disk_cache::EntryImpl::~EntryImpl() (entry_impl.cc:138) ==25173== by 0x81C00DC: base::RefCounted<disk_cache::EntryImpl>::Release() (ref_counted.h:78) ==25173== by 0x81C43F9: disk_cache::EntryImpl::Close() (entry_impl.cc:149) ==25173== by 0x817690A: net::HttpCache::ActiveEntry::~ActiveEntry() (http_cache.cc:157) ==25173== by 0x8177298: net::HttpCache::DeactivateEntry(net::HttpCache::ActiveEntry*) (http_cache.cc:1206) ==25173== by 0x81779D6: net::HttpCache::DestroyEntry(net::HttpCache::ActiveEntry*) (http_cache.cc:1172) ==25173== by 0x81798AE: net::HttpCache::OnProcessPendingQueue(net::HttpCache::ActiveEntry*) (http_cache.cc:1358) ==25173== by 0x817DB3A: void DispatchToMethod<net::HttpCache, void (net::HttpCache::*)(net::HttpCache::ActiveEntry*), net::HttpCache::ActiveEntry*>(net::HttpCache*, void (net::HttpCache::*)(net::HttpCache::ActiveEntry*), Tuple1<net::HttpCache::ActiveEntry*> const&) (tuple.h:393) ==25173== by 0x817DB6C: ScopedRunnableMethodFactory<net::HttpCache>::RunnableMethod<void (net::HttpCache::*)(net::HttpCache::ActiveEntry*), Tuple1<net::HttpCache::ActiveEntry*> >::Run() (task.h:202) -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Chromium-bugs" group. To post to this group, send email to chromium-bugs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/chromium-bugs?hl=en -~----------~----~----~----~------~----~------~--~---