SWDEV-1 - Some 'delete' clean up

Change-Id: I02564f0f0e349375bde1471e9f82df268703367b


[ROCm/clr commit: 73967c3b17]
This commit is contained in:
Jason Tang
2021-09-06 17:55:09 -04:00
committed by Jason Tang
parent 3f5d248508
commit e94aec09bd
13 changed files with 49 additions and 123 deletions
+2 -4
View File
@@ -310,8 +310,7 @@ void HostcallListener::terminate() {
#if defined(__clang__)
#if __has_feature(address_sanitizer)
if (urilocator)
delete urilocator;
delete urilocator;
#endif
#endif
delete doorbell_;
@@ -355,8 +354,7 @@ bool HostcallListener::initialize(const amd::Device &dev) {
delete doorbell_;
#if defined(__clang__)
#if __has_feature(address_sanitizer)
if (urilocator)
delete urilocator;
delete urilocator;
#endif
#endif
return false;
+13 -33
View File
@@ -481,22 +481,14 @@ Device::~Device() {
delete vaCacheMap_;
}
if (vaCacheAccess_) {
delete vaCacheAccess_;
}
delete vaCacheAccess_;
if (arena_mem_obj_ != nullptr) {
arena_mem_obj_->release();
}
// Destroy device settings
if (settings_ != nullptr) {
delete settings_;
}
if (info_.extensions_ != nullptr) {
delete[] info_.extensions_;
}
delete settings_;
delete[] info_.extensions_;
}
bool Device::ValidateComgr() {
@@ -789,12 +781,8 @@ ClBinary::ClBinary(const amd::Device& dev, BinaryImageFormat bifVer)
ClBinary::~ClBinary() {
release();
if (elfIn_) {
delete elfIn_;
}
if (elfOut_) {
delete elfOut_;
}
delete elfIn_;
delete elfOut_;
}
bool ClBinary::setElfTarget() {
@@ -1072,10 +1060,8 @@ bool ClBinary::setElfIn() {
}
elfIn_ = new amd::Elf(ELFCLASSNONE, binary_, size_, nullptr, amd::Elf::ELF_C_READ);
if ((elfIn_ == nullptr) || !elfIn_->isSuccessful()) {
if (elfIn_) {
delete elfIn_;
elfIn_ = nullptr;
}
delete elfIn_;
elfIn_ = nullptr;
LogError("Creating input ELF object failed");
return false;
}
@@ -1084,20 +1070,16 @@ bool ClBinary::setElfIn() {
}
void ClBinary::resetElfIn() {
if (elfIn_) {
delete elfIn_;
elfIn_ = nullptr;
}
delete elfIn_;
elfIn_ = nullptr;
}
bool ClBinary::setElfOut(unsigned char eclass,
const char* outFile, bool tempFile) {
elfOut_ = new amd::Elf(eclass, nullptr, 0, outFile, amd::Elf::ELF_C_WRITE);
if ((elfOut_ == nullptr) || !elfOut_->isSuccessful()) {
if (elfOut_) {
delete elfOut_;
elfOut_ = nullptr;
}
delete elfOut_;
elfOut_ = nullptr;
LogError("Creating ouput ELF object failed");
return false;
}
@@ -1109,10 +1091,8 @@ bool ClBinary::setElfOut(unsigned char eclass,
}
void ClBinary::resetElfOut() {
if (elfOut_) {
delete elfOut_;
elfOut_ = nullptr;
}
delete elfOut_;
elfOut_ = nullptr;
}
bool ClBinary::loadLlvmBinary(std::string& llvmBinary,
+3 -7
View File
@@ -1426,10 +1426,8 @@ bool Program::initClBinary() {
// ================================================================================================
void Program::releaseClBinary() {
if (clBinary_ != nullptr) {
delete clBinary_;
clBinary_ = nullptr;
}
delete clBinary_;
clBinary_ = nullptr;
}
// ================================================================================================
@@ -2171,9 +2169,7 @@ bool Program::initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc
if (!isElf(bin)) {
// Invalid binary.
if (decryptedBin != nullptr) {
delete[] decryptedBin;
}
delete[] decryptedBin;
DevLogError("Bin is not ELF \n");
return false;
}
@@ -59,13 +59,8 @@ PalCounterReference::~PalCounterReference() {
// so we have to lock just this queue
amd::ScopedLock lock(gpu_.execution());
if (layout_ != nullptr) {
delete layout_;
}
if (memory_ != nullptr) {
delete memory_;
}
delete layout_;
delete memory_;
if (nullptr != iPerf()) {
iPerf()->Destroy();
@@ -64,9 +64,7 @@ GpuDebugManager::GpuDebugManager(amd::Device* device)
}
GpuDebugManager::~GpuDebugManager() {
if (nullptr != addressWatch_) {
delete[] addressWatch_;
}
delete[] addressWatch_;
}
void GpuDebugManager::executePreDispatchCallBack(void* aqlPacket, void* toolInfo) {
@@ -269,9 +267,7 @@ void GpuDebugManager::setAddressWatch(uint32_t numWatchPoints, void** watchAddre
// previously allocated size is not big enough, allocate new memory
if (addressWatchSize_ < requiredSize) {
if (nullptr != addressWatch_) { // free the smaller address watch storage
delete[] addressWatch_;
}
delete[] addressWatch_;
addressWatch_ = new HwDbgAddressWatch[numWatchPoints];
addressWatchSize_ = requiredSize;
}
@@ -720,11 +720,9 @@ void RgpCaptureMgr::DestroyRGPTracing() {
delete user_event_;
// Destroy the GPA session
if (trace_.gpa_session_ != nullptr) {
// Util::Destructor(trace_.gpa_session_);
delete trace_.gpa_session_;
trace_.gpa_session_ = nullptr;
}
// Util::Destructor(trace_.gpa_session_);
delete trace_.gpa_session_;
trace_.gpa_session_ = nullptr;
memset(&trace_, 0, sizeof(trace_));
}
@@ -226,9 +226,9 @@ HSAILProgram::~HSAILProgram() {
if (executable_) {
loader_->DestroyExecutable(executable_);
}
if (kernels_) {
delete kernels_;
}
delete kernels_;
if (loader_) {
amd::hsa::loader::Loader::Destroy(loader_);
}
@@ -282,16 +282,14 @@ bool HSAILProgram::createKernels(void* binary, size_t binSize, bool useUniformWo
return false;
}
if (kernelNamesSize > 0) {
char* kernelNames = new char[kernelNamesSize];
std::vector<char> kernelNames(kernelNamesSize);
errorCode = amd::Hsail::QueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES,
nullptr, kernelNames, &kernelNamesSize);
nullptr, kernelNames.data(), &kernelNamesSize);
if (errorCode != ACL_SUCCESS) {
buildLog_ += "Error: Querying of kernel names from the binary failed.\n";
delete[] kernelNames;
return false;
}
std::vector<std::string> vKernels = splitSpaceSeparatedString(kernelNames);
delete[] kernelNames;
std::vector<std::string> vKernels = splitSpaceSeparatedString(kernelNames.data());
for (const auto& it : vKernels) {
std::string kernelName(it);
@@ -974,7 +974,6 @@ bool VirtualGPU::create(bool profiling, uint deviceQueueSize, uint rtCUs,
// Create HSAILPrintf class
printfDbgHSA_ = new PrintfDbgHSA(gpuDevice_);
if (nullptr == printfDbgHSA_) {
delete printfDbgHSA_;
LogError("Could not create PrintfDbgHSA class!");
return false;
}
@@ -1107,13 +1106,8 @@ VirtualGPU::~VirtualGPU() {
{
// Destroy queues
if (nullptr != queues_[MainEngine]) {
delete queues_[MainEngine];
}
if (nullptr != queues_[SdmaEngine]) {
delete queues_[SdmaEngine];
}
delete queues_[MainEngine];
delete queues_[SdmaEngine];
if (nullptr != cmdAllocator_) {
cmdAllocator_->Destroy();
+6 -23
View File
@@ -244,15 +244,9 @@ Device::~Device() {
context_->release();
}
if (info_.extensions_) {
delete[] info_.extensions_;
info_.extensions_ = nullptr;
}
delete[] info_.extensions_;
if (settings_) {
delete settings_;
settings_ = nullptr;
}
delete settings_;
delete[] p2p_agents_list_;
@@ -316,15 +310,8 @@ bool NullDevice::init() {
}
NullDevice::~NullDevice() {
if (info_.extensions_) {
delete[] info_.extensions_;
info_.extensions_ = nullptr;
}
if (settings_) {
delete settings_;
settings_ = nullptr;
}
delete[] info_.extensions_;
delete settings_;
}
hsa_status_t Device::iterateAgentCallback(hsa_agent_t agent, void* data) {
@@ -2914,13 +2901,12 @@ bool Device::findLinkInfo(const hsa_amd_memory_pool_t& pool,
}
// Retrieve link info on the pool.
hsa_amd_memory_pool_link_info_t* link_info = new hsa_amd_memory_pool_link_info_t[hops];
std::vector<hsa_amd_memory_pool_link_info_t> link_info(hops);
hsa_status = hsa_amd_agent_memory_pool_get_info(_bkendDevice, pool,
HSA_AMD_AGENT_MEMORY_POOL_INFO_LINK_INFO, link_info);
HSA_AMD_AGENT_MEMORY_POOL_INFO_LINK_INFO, link_info.data());
if (hsa_status != HSA_STATUS_SUCCESS) {
DevLogPrintfError("Cannot retrieve link info, hsa failed with status: %d", hsa_status);
delete[] link_info;
return false;
}
@@ -2959,14 +2945,11 @@ bool Device::findLinkInfo(const hsa_amd_memory_pool_t& pool,
}
default: {
DevLogPrintfError("Invalid LinkAttribute: %d ", link_attr.first);
delete[] link_info;
return false;
}
}
}
delete[] link_info;
return true;
}
@@ -73,8 +73,7 @@ bool Program::initClBinary(char* binaryIn, size_t size) {
char* decryptedBin;
size_t decryptedSize;
if (!clBinary()->decryptElf(binaryIn, size, &decryptedBin, &decryptedSize, &encryptCode)) {
buildLog_ += "Decrypting ELF Failed ";
buildLog_ += "\n";
buildLog_ += "Decrypting ELF Failed\n";
return false;
}
if (decryptedBin != nullptr) {
@@ -86,11 +85,8 @@ bool Program::initClBinary(char* binaryIn, size_t size) {
// Both 32-bit and 64-bit are allowed!
if (!amd::Elf::isElfMagic(bin)) {
// Invalid binary.
if (decryptedBin != nullptr) {
delete[] decryptedBin;
}
buildLog_ += "Elf Magic failed";
buildLog_ += "\n";
delete[] decryptedBin;
buildLog_ += "Elf Magic failed\n";
return false;
}
@@ -1086,10 +1086,8 @@ VirtualGPU::~VirtualGPU() {
timestamp_ = nullptr;
LogError("There was a timestamp that was not used; deleting.");
}
if (printfdbg_ != nullptr) {
delete printfdbg_;
printfdbg_ = nullptr;
}
delete printfdbg_;
if (0 != schedulerSignal_.handle) {
hsa_signal_destroy(schedulerSignal_);
+2 -7
View File
@@ -89,13 +89,8 @@ Context::~Context() {
it->release();
}
if (properties_ != NULL) {
delete[] properties_;
}
if (glenv_ != NULL) {
delete glenv_;
glenv_ = NULL;
}
delete[] properties_;
delete glenv_;
#if WITH_LIQUID_FLASH
lfTerminate();
+3 -4
View File
@@ -467,12 +467,11 @@ void Program::StubProgramSource(const std::string& app_name) {
size_t size = stub_read.tellg();
stub_read.seekg(0, std::ios::beg);
char* data = new char[size];
stub_read.read(data, size);
std::vector<char> file_data(size);
stub_read.read(file_data.data(), size);
stub_read.close();
sourceCode_.assign(data, size);
delete[] data;
sourceCode_.assign(file_data.data(), size);
} else {
std::fstream stub_write;
stub_write.open(file_name.str().c_str(), (std::fstream::out | std::fstream::binary));