From 6a849eb69042525a2d75bbef8b1315a37d505051 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Mon, 21 Mar 2022 10:57:30 +0000 Subject: [PATCH] SWDEV-327967 - Fix Segmentation fault in hipFree Queue creation and release fails during hipFree causing seg fault if the null queue was not created until then and there is no device memory left. Change-Id: I118b86b58e777dac5415bc9ba0c4e23c986efa7d [ROCm/clr commit: 4a90c3ccafbf6345ea40e6f94e3e8a3d7d2e85f6] --- projects/clr/hipamd/src/hip_memory.cpp | 5 ++++- projects/clr/hipamd/src/hip_stream.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 98ec3f2bf8..f07977772b 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -101,7 +101,10 @@ hipError_t ihipFree(void *ptr) } } else { // Wait on the device, associated with the current memory object - hip::getNullStream(memory_object->getContext())->finish(); + amd::HostQueue* queue = hip::getNullStream(memory_object->getContext()); + if (queue != nullptr) { + queue->finish(); + } deviceID = hip::getDeviceID(memory_object->getContext()); } hip::Stream::syncNonBlockingStreams(deviceID); diff --git a/projects/clr/hipamd/src/hip_stream.cpp b/projects/clr/hipamd/src/hip_stream.cpp index 84d6f60e9a..a8b8b9138c 100644 --- a/projects/clr/hipamd/src/hip_stream.cpp +++ b/projects/clr/hipamd/src/hip_stream.cpp @@ -110,7 +110,9 @@ bool Stream::Create() { queue->vdev()->profilerAttach(isProfilerAttached); device_->SaveQueue(queue); } else if (queue != nullptr) { - queue->release(); + // Queue creation has failed, and virtual device associated with the queue may not be created. + // Just need to delete the queue instance. + delete queue; } return result;