diff options
author | vasilii <vasilii@chromium.org> | 2014-09-19 01:20:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-19 08:20:35 +0000 |
commit | a3b755859b3113c74df16939f124bc42464092b1 (patch) | |
tree | 0481b01eb76cb0f128a35a376a418ec7223aa36e /net/disk_cache/simple/simple_backend_impl.h | |
parent | 48c3e5ebfd2640061ed488216f1d275d17c887bd (diff) | |
download | chromium_src-a3b755859b3113c74df16939f124bc42464092b1.zip chromium_src-a3b755859b3113c74df16939f124bc42464092b1.tar.gz chromium_src-a3b755859b3113c74df16939f124bc42464092b1.tar.bz2 |
Revert of Remove void** from disk_cache interface. (patchset #30 id:650001 of https://codereview.chromium.org/542733002/)
Reason for revert:
Introduced memory leaks on linux asan
http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%281%29/builds/5892:
Direct leak of 80 byte(s) in 2 object(s) allocated from:
#0 0x501ccb in operator new(unsigned long) (/b/build/slave/Linux_ASan_LSan_Tests__1_/build/src/out/Release/net_unittests+0x501ccb)
#1 0x309f8d7 in disk_cache::BackendImpl::OpenNextEntryImpl(void**) net/disk_cache/blockfile/backend_impl.cc:620:5
#2 0x30a02cd in disk_cache::BackendImpl::SyncOpenNextEntry(void**, disk_cache::Entry**) net/disk_cache/blockfile/backend_impl.cc:436:17
#3 0x30d49dd in disk_cache::BackendIO::ExecuteBackendOperation() net/disk_cache/blockfile/in_flight_backend_io.cc:248:17
#4 0x2e3b0bf in Run base/callback.h:401:12
#5 0x2e3b0bf in base::debug::TaskAnnotator::RunTask(char const*, char const*, base::PendingTask const&) base/debug/task_annotator.cc:62
#6 0x2dc22fc in base::MessageLoop::RunTask(base::PendingTask const&) base/message_loop/message_loop.cc:446:3
#7 0x2dc33cc in DeferOrRunPendingTask base/message_loop/message_loop.cc:456:5
#8 0x2dc33cc in base::MessageLoop::DoWork() base/message_loop/message_loop.cc:565
#9 0x2e2361f in base::MessagePumpLibevent::Run(base::MessagePump::Delegate*) base/message_loop/message_pump_libevent.cc:232:21
#10 0x2ddd94b in base::RunLoop::Run() base/run_loop.cc:54:3
#11 0x2dc0bc4 in base::MessageLoop::Run() base/message_loop/message_loop.cc:308:3
#12 0x2e0ad90 in base::Thread::ThreadMain() base/threading/thread.cc:228:5
#13 0x2dfeaf0 in base::(anonymous namespace)::ThreadFunc(void*) base/threading/platform_thread_posix.cc:80:3
#14 0x7fa9f4e0ce99 in start_thread /build/buildd/eglibc-2.15/nptl/pthread_create.c:308
Indirect leak of 64 byte(s) in 2 object(s) allocated from:
#0 0x501ccb in operator new(unsigned long) (/b/build/slave/Linux_ASan_LSan_Tests__1_/build/src/out/Release/net_unittests+0x501ccb)
#1 0x30ebaaf in disk_cache::Rankings::GetNext(disk_cache::StorageBlock<disk_cache::RankingsNode>*, disk_cache::Rankings::List) net/disk_cache/blockfile/rankings.cc:435:5
#2 0x30a219d in disk_cache::BackendImpl::OpenFollowingEntryFromList(disk_cache::Rankings::List, disk_cache::StorageBlock<disk_cache::RankingsNode>**, disk_cache::EntryImpl**) net/disk_cache/blockfile/backend_impl.cc:1694:36
#3 0x309fa3d in disk_cache::BackendImpl::OpenNextEntryImpl(void**) net/disk_cache/blockfile/backend_impl.cc:638:11
#4 0x30a02cd in disk_cache::BackendImpl::SyncOpenNextEntry(void**, disk_cache::Entry**) net/disk_cache/blockfile/backend_impl.cc:436:17
#5 0x30d49dd in disk_cache::BackendIO::ExecuteBackendOperation() net/disk_cache/blockfile/in_flight_backend_io.cc:248:17
#6 0x2e3b0bf in Run base/callback.h:401:12
#7 0x2e3b0bf in base::debug::TaskAnnotator::RunTask(char const*, char const*, base::PendingTask const&) base/debug/task_annotator.cc:62
#8 0x2dc22fc in base::MessageLoop::RunTask(base::PendingTask const&) base/message_loop/message_loop.cc:446:3
#9 0x2dc33cc in DeferOrRunPendingTask base/message_loop/message_loop.cc:456:5
#10 0x2dc33cc in base::MessageLoop::DoWork() base/message_loop/message_loop.cc:565
#11 0x2e2361f in base::MessagePumpLibevent::Run(base::MessagePump::Delegate*) base/message_loop/message_pump_libevent.cc:232:21
#12 0x2ddd94b in base::RunLoop::Run() base/run_loop.cc:54:3
#13 0x2dc0bc4 in base::MessageLoop::Run() base/message_loop/message_loop.cc:308:3
#14 0x2e0ad90 in base::Thread::ThreadMain() base/threading/thread.cc:228:5
#15 0x2dfeaf0 in base::(anonymous namespace)::ThreadFunc(void*) base/threading/platform_thread_posix.cc:80:3
#16 0x7fa9f4e0ce99 in start_thread /build/buildd/eglibc-2.15/nptl/pthread_create.c:308
Indirect leak of 36 byte(s) in 1 object(s) allocated from:
#0 0x501ccb in operator new(unsigned long) (/b/build/slave/Linux_ASan_LSan_Tests__1_/build/src/out/Release/net_unittests+0x501ccb)
#1 0x30c0696 in AllocateData net/disk_cache/blockfile/storage_block-inl.h:179:5
#2 0x30c0696 in disk_cache::StorageBlock<disk_cache::RankingsNode>::Load() net/disk_cache/blockfile/storage_block-inl.h:121
#3 0x30e6fe9 in disk_cache::Rankings::GetRanking(disk_cache::StorageBlock<disk_cache::RankingsNode>*) net/disk_cache/blockfile/rankings.cc:586:8
#4 0x30ebd5a in disk_cache::Rankings::GetNext(disk_cache::StorageBlock<disk_cache::RankingsNode>*, disk_cache::Rankings::List) net/disk_cache/blockfile/rankings.cc:440:8
#5 0x30a219d in disk_cache::BackendImpl::OpenFollowingEntryFromList(disk_cache::Rankings::List, disk_cache::StorageBlock<disk_cache::RankingsNode>**, disk_cache::EntryImpl**) net/disk_cache/blockfile/backend_impl.cc:1694:36
#6 0x309fa3d in disk_cache::BackendImpl::OpenNextEntryImpl(void**) net/disk_cache/blockfile/backend_impl.cc:638:11
#7 0x30a02cd in disk_cache::BackendImpl::SyncOpenNextEntry(void**, disk_cache::Entry**) net/disk_cache/blockfile/backend_impl.cc:436:17
#8 0x30d49dd in disk_cache::BackendIO::ExecuteBackendOperation() net/disk_cache/blockfile/in_flight_backend_io.cc:248:17
#9 0x2e3b0bf in Run base/callback.h:401:12
#10 0x2e3b0bf in base::debug::TaskAnnotator::RunTask(char const*, char const*, base::PendingTask const&) base/debug/task_annotator.cc:62
#11 0x2dc22fc in base::MessageLoop::RunTask(base::PendingTask const&) base/message_loop/message_loop.cc:446:3
#12 0x2dc33cc in DeferOrRunPendingTask base/message_loop/message_loop.cc:456:5
#13 0x2dc33cc in base::MessageLoop::DoWork() base/message_loop/message_loop.cc:565
#14 0x2e2361f in base::MessagePumpLibevent::Run(base::MessagePump::Delegate*) base/message_loop/message_pump_libevent.cc:232:21
#15 0x2ddd94b in base::RunLoop::Run() base/run_loop.cc:54:3
#16 0x2dc0bc4 in base::MessageLoop::Run() base/message_loop/message_loop.cc:308:3
#17 0x2e0ad90 in base::Thread::ThreadMain() base/threading/thread.cc:228:5
#18 0x2dfeaf0 in base::(anonymous namespace)::ThreadFunc(void*) base/threading/platform_thread_posix.cc:80:3
#19 0x7fa9f4e0ce99 in start_thread /build/buildd/eglibc-2.15/nptl/pthread_create.c:308
Original issue's description:
> Remove void** from disk_cache interface.
>
> Enumeration and iteration were passing around void**. With this CL, we
> instead use an Iterator object.
>
> R=clamy@chromium.org,jkarlin@chromium.org,jsbell@chromium.org
> BUG=413644
>
> Committed: https://crrev.com/732c8306d4864296511e7a3a252724b1bb34c342
> Cr-Commit-Position: refs/heads/master@{#295659}
TBR=clamy@chromium.org,jkarlin@chromium.org,jsbell@chromium.org,rvargas@chromium.org,pasko@chromium.org,piman@chromium.org,michaeln@chromium.org,cbentzel@chromium.org,gavinp@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=413644
Review URL: https://codereview.chromium.org/585833002
Cr-Commit-Position: refs/heads/master@{#295677}
Diffstat (limited to 'net/disk_cache/simple/simple_backend_impl.h')
-rw-r--r-- | net/disk_cache/simple/simple_backend_impl.h | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/net/disk_cache/simple/simple_backend_impl.h b/net/disk_cache/simple/simple_backend_impl.h index 48c422f..907ee5a 100644 --- a/net/disk_cache/simple/simple_backend_impl.h +++ b/net/disk_cache/simple/simple_backend_impl.h @@ -13,6 +13,7 @@ #include "base/compiler_specific.h" #include "base/containers/hash_tables.h" #include "base/files/file_path.h" +#include "base/id_map.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" @@ -34,11 +35,6 @@ namespace disk_cache { // files. // See http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend // -// The SimpleBackendImpl provides safe iteration; mutating entries during -// iteration cannot cause a crash. It is undefined whether entries created or -// destroyed during the iteration will be included in any pre-existing -// iterations. -// // The non-static functions below must be called on the IO thread unless // otherwise stated. @@ -102,17 +98,18 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, const CompletionCallback& callback) OVERRIDE; virtual int DoomEntriesSince(base::Time initial_time, const CompletionCallback& callback) OVERRIDE; - virtual scoped_ptr<Iterator> CreateIterator() OVERRIDE; + virtual int OpenNextEntry(void** iter, Entry** next_entry, + const CompletionCallback& callback) OVERRIDE; + virtual void EndEnumeration(void** iter) OVERRIDE; virtual void GetStats( std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; private: - class SimpleIterator; - friend class SimpleIterator; - typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap; + typedef IDMap<std::vector<uint64>, IDMapOwnPointer> ActiveEnumerationMap; + typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> InitializeIndexCallback; @@ -127,6 +124,17 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, int net_error; }; + // Convert an iterator from OpenNextEntry() to the key type for + // ActiveEnumerationMap. Note it takes a void** argument; this is for safety; + // if it took a void*, that would be type compatible with a void** permitting + // easy calls missing the dereference. + static ActiveEnumerationMap::KeyType IteratorToEnumerationId(void** iter); + + // Convert a key from ActiveEnumerationMap back to a void*, suitable for + // storing in the iterator argument to OpenNextEntry(). + static void* EnumerationIdToIterator( + ActiveEnumerationMap::KeyType enumeration_id); + void InitializeIndex(const CompletionCallback& callback, const DiskStatResult& result); @@ -161,6 +169,14 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, // which is very important to prevent races in DoomEntries() above. int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback); + // Called when the index is initilized to find the next entry in the iterator + // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED + // is returned. Otherwise, calls OpenEntryFromHash. + void GetNextEntryInIterator(void** iter, + Entry** next_entry, + const CompletionCallback& callback, + int error_code); + // Called when we tried to open an entry with hash alone. When a blank entry // has been created and filled in with information from the disk - based on a // hash alone - this checks that a duplicate active entry was not created @@ -179,6 +195,14 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, const CompletionCallback& callback, int error_code); + // Called at the end of the asynchronous operation triggered by + // OpenEntryFromHash. Makes sure to continue iterating if the open entry was + // not a success. + void CheckIterationReturnValue(void** iter, + Entry** entry, + const CompletionCallback& callback, + int error_code); + // A callback thunk used by DoomEntries to clear the |entries_pending_doom_| // after a mass doom. void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes, @@ -196,6 +220,9 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, EntryMap active_entries_; + // One entry for every enumeration in progress. + ActiveEnumerationMap active_enumerations_; + // The set of all entries which are currently being doomed. To avoid races, // these entries cannot have Doom/Create/Open operations run until the doom // is complete. The base::Closure map target is used to store deferred |