From 904d3fd3ba12ce473c4d2f8ea755e010949a6013 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 31 Jan 2023 17:46:15 +0000 Subject: [PATCH] SWDEV-380258 - Fix invalid iterator after erase Fix rare segfault due to invalid iterator after erase Change-Id: Id5b54d6cf10075deff0d613fec12af249c6c55a3 [ROCm/clr commit: 08d72c4f989dd6e7d15b1c28c611b3a798079584] --- projects/clr/rocclr/device/rocm/rocdevice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 85aa32a68d..01c038c9d6 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -236,17 +236,17 @@ Device::~Device() { } for (auto& it : queuePool_) { - for (auto& qIter : it) { - hsa_queue_t* queue = qIter.first; - auto& qInfo = qIter.second; + for (auto qIter = it.begin(); qIter != it.end(); ) { + hsa_queue_t* queue = qIter->first; + auto& qInfo = qIter->second; if (qInfo.hostcallBuffer_) { ClPrint(amd::LOG_INFO, amd::LOG_QUEUE, "deleting hostcall buffer %p for hardware queue %p", - qInfo.hostcallBuffer_, qIter.first); + qInfo.hostcallBuffer_, qIter->first); disableHostcalls(qInfo.hostcallBuffer_); context().svmFree(qInfo.hostcallBuffer_); } ClPrint(amd::LOG_INFO, amd::LOG_QUEUE, "deleting hardware queue %p with refCount 0", queue); - it.erase(queue); + qIter = it.erase(qIter); hsa_queue_destroy(queue); } }