diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2014-06-09 13:23:03 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2014-06-09 14:40:30 -0400 |
commit | af4f086490d6ae51aa0c252df26751385683eaaa (patch) | |
tree | d4ab13dda5b4e5a83e12cb6c59d62f8179e18e04 /src/mongo/util/mmap_win.cpp | |
parent | db085c742b1b97dc70a301c1d575ffd852d3ae1e (diff) | |
download | mongo-af4f086490d6ae51aa0c252df26751385683eaaa.tar.gz |
SERVER-14198: Fix memory allocation reuse
In std::set<Pointer>, Pointer to a memory address is not a unique key.
Mmap_posix already used a unique key in the case memory was reused.
Added the same change to mmap_win.
Diffstat (limited to 'src/mongo/util/mmap_win.cpp')
-rw-r--r-- | src/mongo/util/mmap_win.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/mongo/util/mmap_win.cpp b/src/mongo/util/mmap_win.cpp index 6f2639431ae..27f72ce5e1c 100644 --- a/src/mongo/util/mmap_win.cpp +++ b/src/mongo/util/mmap_win.cpp @@ -39,6 +39,10 @@ namespace mongo { + namespace { + mongo::AtomicUInt64 mmfNextId(0); + } + static size_t fetchMinOSPageSizeBytes() { SYSTEM_INFO si; GetSystemInfo(&si); @@ -132,7 +136,7 @@ namespace mongo { } MemoryMappedFile::MemoryMappedFile() - : _uniqueId(0) { + : _uniqueId(mmfNextId.fetchAndAdd(1)) { fd = 0; maphandle = 0; len = 0; @@ -486,9 +490,10 @@ namespace mongo { WindowsFlushable( MemoryMappedFile* theFile, void * view, HANDLE fd, + const uint64_t id, const std::string& filename, boost::mutex& flushMutex ) - : _theFile(theFile), _view(view), _fd(fd), _filename(filename), + : _theFile(theFile), _view(view), _fd(fd), _id(id), _filename(filename), _flushMutex(flushMutex) {} @@ -498,7 +503,10 @@ namespace mongo { { LockMongoFilesShared mmfilesLock; - if ( MongoFile::getAllFiles().count(_theFile) == 0 ) { + + std::set<MongoFile*> mmfs = MongoFile::getAllFiles(); + std::set<MongoFile*>::const_iterator it = mmfs.find(_theFile); + if ( it == mmfs.end() || (*it)->getUniqueId() != _id ) { // this was deleted while we were unlocked return; } @@ -570,6 +578,7 @@ namespace mongo { MemoryMappedFile* _theFile; // this may be deleted while we are running void * _view; HANDLE _fd; + const uint64_t _id; string _filename; boost::mutex& _flushMutex; }; @@ -577,13 +586,13 @@ namespace mongo { void MemoryMappedFile::flush(bool sync) { uassert(13056, "Async flushing not supported on windows", sync); if( !views.empty() ) { - WindowsFlushable f(this, viewForFlushing(), fd, filename(), _flushMutex); + WindowsFlushable f(this, viewForFlushing(), fd, _uniqueId, filename(), _flushMutex); f.flush(); } } MemoryMappedFile::Flushable * MemoryMappedFile::prepareFlush() { - return new WindowsFlushable(this, viewForFlushing(), fd, + return new WindowsFlushable(this, viewForFlushing(), fd, _uniqueId, filename(), _flushMutex); } |