From 8f9da259ac458a540db2eb4e8d71b136e9b99a9f Mon Sep 17 00:00:00 2001 From: jofrn Date: Tue, 11 Nov 2025 16:48:06 -0500 Subject: [PATCH] Fix memory leak in hip_fatbin.cpp UncompressAndPopulateCodeObject (#1692) Wrap amd_comgr_data_t item returned from action_data_get_data() in ComgrDataUniqueHandle to ensure it gets released. --- projects/clr/hipamd/src/hip_fatbin.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/src/hip_fatbin.cpp b/projects/clr/hipamd/src/hip_fatbin.cpp index fd9b059c5c..9df386c173 100644 --- a/projects/clr/hipamd/src/hip_fatbin.cpp +++ b/projects/clr/hipamd/src/hip_fatbin.cpp @@ -349,9 +349,10 @@ static bool UncompressAndPopulateCodeObject( LogError("Failed to get data unbundled code object"); break; } + comgr_helper::ComgrDataUniqueHandle item_handle(item); size_t item_name_size = 0; - if (auto comgr_status = amd::Comgr::get_data_name(item, &item_name_size, nullptr); + if (auto comgr_status = amd::Comgr::get_data_name(item_handle.get(), &item_name_size, nullptr); comgr_status != AMD_COMGR_STATUS_SUCCESS) { LogError("Failed to get data size"); break; @@ -359,14 +360,14 @@ static bool UncompressAndPopulateCodeObject( std::string item_bundle_id(item_name_size, 0); if (auto comgr_status = - amd::Comgr::get_data_name(item, &item_name_size, item_bundle_id.data()); + amd::Comgr::get_data_name(item_handle.get(), &item_name_size, item_bundle_id.data()); comgr_status != AMD_COMGR_STATUS_SUCCESS) { LogError("Failed to get data"); break; } size_t item_size = 0; - if (auto comgr_status = amd::Comgr::get_data(item, &item_size, nullptr); + if (auto comgr_status = amd::Comgr::get_data(item_handle.get(), &item_size, nullptr); comgr_status != AMD_COMGR_STATUS_SUCCESS) { LogError("Failed to get data size"); break; @@ -374,7 +375,7 @@ static bool UncompressAndPopulateCodeObject( if (item_size > 0) { char* item_data = new char[item_size]; - if (auto comgr_status = amd::Comgr::get_data(item, &item_size, item_data); + if (auto comgr_status = amd::Comgr::get_data(item_handle.get(), &item_size, item_data); comgr_status != AMD_COMGR_STATUS_SUCCESS) { LogError("Failed to get data"); break;