SWDEV-569319 Fix dangling reference warning (#2509)
* SWDEV-569319 Fix dangling reference warning * fix nullptr warning * use emplace * return regular pointer
This commit is contained in:
@@ -362,11 +362,11 @@ namespace code {
|
||||
|
||||
class AmdHsaCodeManager {
|
||||
private:
|
||||
typedef std::unordered_map<uint64_t, std::shared_ptr<AmdHsaCode>> CodeMap;
|
||||
typedef std::unordered_map<uint64_t, std::unique_ptr<AmdHsaCode>> CodeMap;
|
||||
CodeMap codeMap;
|
||||
|
||||
public:
|
||||
const std::shared_ptr<AmdHsaCode>& FromHandle(hsa_code_object_t handle);
|
||||
AmdHsaCode* FromHandle(hsa_code_object_t handle);
|
||||
bool Destroy(hsa_code_object_t handle);
|
||||
};
|
||||
|
||||
|
||||
@@ -1804,7 +1804,7 @@ hsa_status_t hsa_code_object_serialize(
|
||||
IS_BAD_PTR(serialized_code_object);
|
||||
IS_BAD_PTR(serialized_code_object_size);
|
||||
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get();
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object);
|
||||
if (!code) {
|
||||
return HSA_STATUS_ERROR_INVALID_CODE_OBJECT;
|
||||
}
|
||||
@@ -1982,7 +1982,7 @@ hsa_status_t hsa_code_object_get_info(
|
||||
IS_OPEN();
|
||||
IS_BAD_PTR(value);
|
||||
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get();
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object);
|
||||
if (!code) {
|
||||
return HSA_STATUS_ERROR_INVALID_CODE_OBJECT;
|
||||
}
|
||||
@@ -2039,7 +2039,7 @@ hsa_status_t hsa_code_object_get_symbol(
|
||||
IS_BAD_PTR(symbol_name);
|
||||
IS_BAD_PTR(symbol);
|
||||
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get();
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object);
|
||||
if (!code) {
|
||||
return HSA_STATUS_ERROR_INVALID_CODE_OBJECT;
|
||||
}
|
||||
@@ -2059,7 +2059,7 @@ hsa_status_t hsa_code_object_get_symbol_from_name(
|
||||
IS_BAD_PTR(symbol_name);
|
||||
IS_BAD_PTR(symbol);
|
||||
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get();
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object);
|
||||
if (!code) {
|
||||
return HSA_STATUS_ERROR_INVALID_CODE_OBJECT;
|
||||
}
|
||||
@@ -2097,7 +2097,7 @@ hsa_status_t hsa_code_object_iterate_symbols(
|
||||
IS_OPEN();
|
||||
IS_BAD_PTR(callback);
|
||||
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get();
|
||||
amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object);
|
||||
if (!code) {
|
||||
return HSA_STATUS_ERROR_INVALID_CODE_OBJECT;
|
||||
}
|
||||
|
||||
@@ -1742,19 +1742,19 @@ namespace code {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::shared_ptr<AmdHsaCode>& AmdHsaCodeManager::FromHandle(hsa_code_object_t c)
|
||||
AmdHsaCode* AmdHsaCodeManager::FromHandle(hsa_code_object_t c)
|
||||
{
|
||||
CodeMap::iterator i = codeMap.find(c.handle);
|
||||
if (i == codeMap.end()) {
|
||||
std::shared_ptr<AmdHsaCode> code = std::make_shared<AmdHsaCode>();
|
||||
std::unique_ptr<AmdHsaCode> code = std::make_unique<AmdHsaCode>();
|
||||
const void* buffer = reinterpret_cast<const void*>(c.handle);
|
||||
if (!code->InitAsBuffer(buffer, 0)) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
codeMap[c.handle] = code;
|
||||
return code;
|
||||
auto res = codeMap.emplace(c.handle, std::move(code));
|
||||
return res.first->second.get();
|
||||
}
|
||||
return i->second;
|
||||
return i->second.get();
|
||||
}
|
||||
|
||||
bool AmdHsaCodeManager::Destroy(hsa_code_object_t c)
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user