From 293092f32fd7052fed2746c7da4467e2d4e1e632 Mon Sep 17 00:00:00 2001 From: Sunday Clement Date: Thu, 29 May 2025 10:47:12 -0400 Subject: [PATCH] rocr: Fix Resource Leak allocated memory was previously not freed in the event of an error with rwlock initialization. Signed-off-by: Sunday Clement --- runtime/hsa-runtime/core/util/lnx/os_linux.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 4d62979829..88e860b890 100644 --- a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -717,15 +717,15 @@ SharedMutex CreateSharedMutex() { } #endif - pthread_rwlock_t* lock = new pthread_rwlock_t; - err = pthread_rwlock_init(lock, &attrib); + std::unique_ptr lock(new pthread_rwlock_t); + err = pthread_rwlock_init(lock.get(), &attrib); if (err != 0) { fprintf(stderr, "rw lock init failed: %s\n", strerror(err)); return nullptr; } pthread_rwlockattr_destroy(&attrib); - return lock; + return lock.release(); } bool TryAcquireSharedMutex(SharedMutex lock) {