diff --git a/arangod/Pregel/TypedBuffer.h b/arangod/Pregel/TypedBuffer.h index 36abd29179..ef8f6d0a5e 100644 --- a/arangod/Pregel/TypedBuffer.h +++ b/arangod/Pregel/TypedBuffer.h @@ -42,7 +42,7 @@ namespace pregel { template struct TypedBuffer { /// close file (see close() ) - virtual ~TypedBuffer(){}; + virtual ~TypedBuffer() {} TypedBuffer() : _ptr(nullptr) {} /// @brief return whether the datafile is a physical file (true) or an @@ -112,7 +112,7 @@ template class MappedFileBuffer : public TypedBuffer { public: #ifdef TRI_HAVE_ANONYMOUS_MMAP - MappedFileBuffer(size_t entries) : _size(entries) { + explicit MappedFileBuffer(size_t entries) : _size(entries) { #ifdef TRI_MMAP_ANONYMOUS // fd -1 is required for "real" anonymous regions _fd = -1; @@ -156,7 +156,7 @@ class MappedFileBuffer : public TypedBuffer { // ptr); } #else - MappedFileBuffer(size_t entries) : _size(entries) { + explicit MappedFileBuffer(size_t entries) : _size(entries) { double tt = TRI_microtime(); std::string file = "pregel_" + std::to_string((uint64_t)tt) + ".mmap"; std::string filename = FileUtils::buildFilename(TRI_GetTempPath(), file); @@ -223,6 +223,11 @@ class MappedFileBuffer : public TypedBuffer { /// close file void close() override { + if (this->_ptr == nullptr) { + // already closed or not opened + return; + } + int res = TRI_UNMMFile(this->_ptr, _mappedSize, _fd, &_mmHandle); if (res != TRI_ERROR_NO_ERROR) { // leave file open here as it will still be memory-mapped diff --git a/lib/Basics/memory-map-win32.cpp b/lib/Basics/memory-map-win32.cpp index 06e286aad8..eaedf3020e 100644 --- a/lib/Basics/memory-map-win32.cpp +++ b/lib/Basics/memory-map-win32.cpp @@ -256,7 +256,16 @@ int TRI_UNMMFile(void* memoryAddress, size_t numOfBytesToUnMap, // UnmapViewOfFile: If the function succeeds, the return value is nonzero. bool ok = (UnmapViewOfFile(memoryAddress) != 0); - ok = (CloseHandle(*mmHandle) && ok); + if (!ok) { + DWORD errorCode = GetLastError(); + LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "UnmapViewOfFile returned an error: " << errorCode; + } + + if (CloseHandle(*mmHandle) == 0) { + DWORD errorCode = GetLastError(); + LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "CloseHandle returned an error: " << errorCode; + ok = false; + } if (!ok) { return TRI_ERROR_SYS_ERROR; diff --git a/tests/Pregel/typedbuffer.cpp b/tests/Pregel/typedbuffer.cpp index 17cfff68f0..a3a2082422 100644 --- a/tests/Pregel/typedbuffer.cpp +++ b/tests/Pregel/typedbuffer.cpp @@ -74,4 +74,3 @@ TEST_CASE("tst_pregel1", "[pregel][mmap]") { REQUIRE(mapped.data() == nullptr); } -/* end of georeg.cpp */