diff --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp --- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp @@ -305,7 +305,8 @@ auto Reservation = std::lower_bound( Reservations.rbegin(), Reservations.rend(), AI.MappingBase, [](const auto &A, const auto &B) { return A.first > B; }); - assert(Reservation != Reservations.rend() && "Attempt to initialize unreserved range"); + assert(Reservation != Reservations.rend() && + "Attempt to initialize unreserved range"); tpctypes::SharedMemoryFinalizeRequest FR; @@ -418,10 +419,9 @@ #elif defined(_WIN32) - UnmapViewOfFile(R.second.LocalAddr); + UnmapViewOfFile(R.second.LocalAddr); #endif - } } diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp @@ -198,6 +198,17 @@ AllErr = joinErrors(std::move(AllErr), std::move(Err)); } + // Remove the allocation from the allocation list of its reservation + for (auto &Reservation : Reservations) { + auto AllocationIt = + std::find(Reservation.second.Allocations.begin(), + Reservation.second.Allocations.end(), Base); + if (AllocationIt != Reservation.second.Allocations.end()) { + Reservation.second.Allocations.erase(AllocationIt); + break; + } + } + Allocations.erase(Base); } } @@ -264,22 +275,15 @@ } Error ExecutorSharedMemoryMapperService::shutdown() { - std::vector ReservationAddrs; - { - std::lock_guard Lock(Mutex); + if (Reservations.empty()) + return Error::success(); - if (Reservations.empty()) - return Error::success(); - - ReservationAddrs.reserve(Reservations.size()); - for (const auto &R : Reservations) { - ReservationAddrs.push_back(ExecutorAddr::fromPtr(R.getFirst())); - } - - Reservations.clear(); - } + std::vector ReservationAddrs; + ReservationAddrs.reserve(Reservations.size()); + for (const auto &R : Reservations) + ReservationAddrs.push_back(ExecutorAddr::fromPtr(R.getFirst())); - return release(ReservationAddrs); + return release(std::move(ReservationAddrs)); } void ExecutorSharedMemoryMapperService::addBootstrapSymbols(