Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit bc664b4

Browse files
JasonTTangJason Tang
authored andcommitted
SWDEV-1 - Some 'delete' clean up
Change-Id: I02564f0f0e349375bde1471e9f82df268703367b
1 parent f0ab032 commit bc664b4

File tree

13 files changed

+49
-123
lines changed

13 files changed

+49
-123
lines changed

device/devhostcall.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ void HostcallListener::terminate() {
310310

311311
#if defined(__clang__)
312312
#if __has_feature(address_sanitizer)
313-
if (urilocator)
314-
delete urilocator;
313+
delete urilocator;
315314
#endif
316315
#endif
317316
delete doorbell_;
@@ -355,8 +354,7 @@ bool HostcallListener::initialize(const amd::Device &dev) {
355354
delete doorbell_;
356355
#if defined(__clang__)
357356
#if __has_feature(address_sanitizer)
358-
if (urilocator)
359-
delete urilocator;
357+
delete urilocator;
360358
#endif
361359
#endif
362360
return false;

device/device.cpp

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -481,22 +481,14 @@ Device::~Device() {
481481
delete vaCacheMap_;
482482
}
483483

484-
if (vaCacheAccess_) {
485-
delete vaCacheAccess_;
486-
}
484+
delete vaCacheAccess_;
487485

488486
if (arena_mem_obj_ != nullptr) {
489487
arena_mem_obj_->release();
490488
}
491489

492-
// Destroy device settings
493-
if (settings_ != nullptr) {
494-
delete settings_;
495-
}
496-
497-
if (info_.extensions_ != nullptr) {
498-
delete[] info_.extensions_;
499-
}
490+
delete settings_;
491+
delete[] info_.extensions_;
500492
}
501493

502494
bool Device::ValidateComgr() {
@@ -789,12 +781,8 @@ ClBinary::ClBinary(const amd::Device& dev, BinaryImageFormat bifVer)
789781
ClBinary::~ClBinary() {
790782
release();
791783

792-
if (elfIn_) {
793-
delete elfIn_;
794-
}
795-
if (elfOut_) {
796-
delete elfOut_;
797-
}
784+
delete elfIn_;
785+
delete elfOut_;
798786
}
799787

800788
bool ClBinary::setElfTarget() {
@@ -1072,10 +1060,8 @@ bool ClBinary::setElfIn() {
10721060
}
10731061
elfIn_ = new amd::Elf(ELFCLASSNONE, binary_, size_, nullptr, amd::Elf::ELF_C_READ);
10741062
if ((elfIn_ == nullptr) || !elfIn_->isSuccessful()) {
1075-
if (elfIn_) {
1076-
delete elfIn_;
1077-
elfIn_ = nullptr;
1078-
}
1063+
delete elfIn_;
1064+
elfIn_ = nullptr;
10791065
LogError("Creating input ELF object failed");
10801066
return false;
10811067
}
@@ -1084,20 +1070,16 @@ bool ClBinary::setElfIn() {
10841070
}
10851071

10861072
void ClBinary::resetElfIn() {
1087-
if (elfIn_) {
1088-
delete elfIn_;
1089-
elfIn_ = nullptr;
1090-
}
1073+
delete elfIn_;
1074+
elfIn_ = nullptr;
10911075
}
10921076

10931077
bool ClBinary::setElfOut(unsigned char eclass,
10941078
const char* outFile, bool tempFile) {
10951079
elfOut_ = new amd::Elf(eclass, nullptr, 0, outFile, amd::Elf::ELF_C_WRITE);
10961080
if ((elfOut_ == nullptr) || !elfOut_->isSuccessful()) {
1097-
if (elfOut_) {
1098-
delete elfOut_;
1099-
elfOut_ = nullptr;
1100-
}
1081+
delete elfOut_;
1082+
elfOut_ = nullptr;
11011083
LogError("Creating ouput ELF object failed");
11021084
return false;
11031085
}
@@ -1109,10 +1091,8 @@ bool ClBinary::setElfOut(unsigned char eclass,
11091091
}
11101092

11111093
void ClBinary::resetElfOut() {
1112-
if (elfOut_) {
1113-
delete elfOut_;
1114-
elfOut_ = nullptr;
1115-
}
1094+
delete elfOut_;
1095+
elfOut_ = nullptr;
11161096
}
11171097

11181098
bool ClBinary::loadLlvmBinary(std::string& llvmBinary,

device/devprogram.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,8 @@ bool Program::initClBinary() {
14261426

14271427
// ================================================================================================
14281428
void Program::releaseClBinary() {
1429-
if (clBinary_ != nullptr) {
1430-
delete clBinary_;
1431-
clBinary_ = nullptr;
1432-
}
1429+
delete clBinary_;
1430+
clBinary_ = nullptr;
14331431
}
14341432

14351433
// ================================================================================================
@@ -2171,9 +2169,7 @@ bool Program::initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc
21712169

21722170
if (!isElf(bin)) {
21732171
// Invalid binary.
2174-
if (decryptedBin != nullptr) {
2175-
delete[] decryptedBin;
2176-
}
2172+
delete[] decryptedBin;
21772173
DevLogError("Bin is not ELF \n");
21782174
return false;
21792175
}

device/pal/palcounters.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ PalCounterReference::~PalCounterReference() {
5959
// so we have to lock just this queue
6060
amd::ScopedLock lock(gpu_.execution());
6161

62-
if (layout_ != nullptr) {
63-
delete layout_;
64-
}
65-
66-
if (memory_ != nullptr) {
67-
delete memory_;
68-
}
62+
delete layout_;
63+
delete memory_;
6964

7065
if (nullptr != iPerf()) {
7166
iPerf()->Destroy();

device/pal/paldebugmanager.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ GpuDebugManager::GpuDebugManager(amd::Device* device)
6464
}
6565

6666
GpuDebugManager::~GpuDebugManager() {
67-
if (nullptr != addressWatch_) {
68-
delete[] addressWatch_;
69-
}
67+
delete[] addressWatch_;
7068
}
7169

7270
void GpuDebugManager::executePreDispatchCallBack(void* aqlPacket, void* toolInfo) {
@@ -269,9 +267,7 @@ void GpuDebugManager::setAddressWatch(uint32_t numWatchPoints, void** watchAddre
269267

270268
// previously allocated size is not big enough, allocate new memory
271269
if (addressWatchSize_ < requiredSize) {
272-
if (nullptr != addressWatch_) { // free the smaller address watch storage
273-
delete[] addressWatch_;
274-
}
270+
delete[] addressWatch_;
275271
addressWatch_ = new HwDbgAddressWatch[numWatchPoints];
276272
addressWatchSize_ = requiredSize;
277273
}

device/pal/palgpuopen.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,9 @@ void RgpCaptureMgr::DestroyRGPTracing() {
720720
delete user_event_;
721721

722722
// Destroy the GPA session
723-
if (trace_.gpa_session_ != nullptr) {
724-
// Util::Destructor(trace_.gpa_session_);
725-
delete trace_.gpa_session_;
726-
trace_.gpa_session_ = nullptr;
727-
}
723+
// Util::Destructor(trace_.gpa_session_);
724+
delete trace_.gpa_session_;
725+
trace_.gpa_session_ = nullptr;
728726

729727
memset(&trace_, 0, sizeof(trace_));
730728
}

device/pal/palprogram.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ HSAILProgram::~HSAILProgram() {
226226
if (executable_) {
227227
loader_->DestroyExecutable(executable_);
228228
}
229-
if (kernels_) {
230-
delete kernels_;
231-
}
229+
230+
delete kernels_;
231+
232232
if (loader_) {
233233
amd::hsa::loader::Loader::Destroy(loader_);
234234
}
@@ -282,16 +282,14 @@ bool HSAILProgram::createKernels(void* binary, size_t binSize, bool useUniformWo
282282
return false;
283283
}
284284
if (kernelNamesSize > 0) {
285-
char* kernelNames = new char[kernelNamesSize];
285+
std::vector<char> kernelNames(kernelNamesSize);
286286
errorCode = amd::Hsail::QueryInfo(palNullDevice().compiler(), binaryElf_, RT_KERNEL_NAMES,
287-
nullptr, kernelNames, &kernelNamesSize);
287+
nullptr, kernelNames.data(), &kernelNamesSize);
288288
if (errorCode != ACL_SUCCESS) {
289289
buildLog_ += "Error: Querying of kernel names from the binary failed.\n";
290-
delete[] kernelNames;
291290
return false;
292291
}
293-
std::vector<std::string> vKernels = splitSpaceSeparatedString(kernelNames);
294-
delete[] kernelNames;
292+
std::vector<std::string> vKernels = splitSpaceSeparatedString(kernelNames.data());
295293
for (const auto& it : vKernels) {
296294
std::string kernelName(it);
297295

device/pal/palvirtual.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,6 @@ bool VirtualGPU::create(bool profiling, uint deviceQueueSize, uint rtCUs,
974974
// Create HSAILPrintf class
975975
printfDbgHSA_ = new PrintfDbgHSA(gpuDevice_);
976976
if (nullptr == printfDbgHSA_) {
977-
delete printfDbgHSA_;
978977
LogError("Could not create PrintfDbgHSA class!");
979978
return false;
980979
}
@@ -1107,13 +1106,8 @@ VirtualGPU::~VirtualGPU() {
11071106

11081107
{
11091108
// Destroy queues
1110-
if (nullptr != queues_[MainEngine]) {
1111-
delete queues_[MainEngine];
1112-
}
1113-
1114-
if (nullptr != queues_[SdmaEngine]) {
1115-
delete queues_[SdmaEngine];
1116-
}
1109+
delete queues_[MainEngine];
1110+
delete queues_[SdmaEngine];
11171111

11181112
if (nullptr != cmdAllocator_) {
11191113
cmdAllocator_->Destroy();

device/rocm/rocdevice.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,9 @@ Device::~Device() {
244244
context_->release();
245245
}
246246

247-
if (info_.extensions_) {
248-
delete[] info_.extensions_;
249-
info_.extensions_ = nullptr;
250-
}
247+
delete[] info_.extensions_;
251248

252-
if (settings_) {
253-
delete settings_;
254-
settings_ = nullptr;
255-
}
249+
delete settings_;
256250

257251
delete[] p2p_agents_list_;
258252

@@ -316,15 +310,8 @@ bool NullDevice::init() {
316310
}
317311

318312
NullDevice::~NullDevice() {
319-
if (info_.extensions_) {
320-
delete[] info_.extensions_;
321-
info_.extensions_ = nullptr;
322-
}
323-
324-
if (settings_) {
325-
delete settings_;
326-
settings_ = nullptr;
327-
}
313+
delete[] info_.extensions_;
314+
delete settings_;
328315
}
329316

330317
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,
29142901
}
29152902

29162903
// Retrieve link info on the pool.
2917-
hsa_amd_memory_pool_link_info_t* link_info = new hsa_amd_memory_pool_link_info_t[hops];
2904+
std::vector<hsa_amd_memory_pool_link_info_t> link_info(hops);
29182905
hsa_status = hsa_amd_agent_memory_pool_get_info(_bkendDevice, pool,
2919-
HSA_AMD_AGENT_MEMORY_POOL_INFO_LINK_INFO, link_info);
2906+
HSA_AMD_AGENT_MEMORY_POOL_INFO_LINK_INFO, link_info.data());
29202907

29212908
if (hsa_status != HSA_STATUS_SUCCESS) {
29222909
DevLogPrintfError("Cannot retrieve link info, hsa failed with status: %d", hsa_status);
2923-
delete[] link_info;
29242910
return false;
29252911
}
29262912

@@ -2959,14 +2945,11 @@ bool Device::findLinkInfo(const hsa_amd_memory_pool_t& pool,
29592945
}
29602946
default: {
29612947
DevLogPrintfError("Invalid LinkAttribute: %d ", link_attr.first);
2962-
delete[] link_info;
29632948
return false;
29642949
}
29652950
}
29662951
}
29672952

2968-
delete[] link_info;
2969-
29702953
return true;
29712954
}
29722955

device/rocm/rocprogram.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ bool Program::initClBinary(char* binaryIn, size_t size) {
7373
char* decryptedBin;
7474
size_t decryptedSize;
7575
if (!clBinary()->decryptElf(binaryIn, size, &decryptedBin, &decryptedSize, &encryptCode)) {
76-
buildLog_ += "Decrypting ELF Failed ";
77-
buildLog_ += "\n";
76+
buildLog_ += "Decrypting ELF Failed\n";
7877
return false;
7978
}
8079
if (decryptedBin != nullptr) {
@@ -86,11 +85,8 @@ bool Program::initClBinary(char* binaryIn, size_t size) {
8685
// Both 32-bit and 64-bit are allowed!
8786
if (!amd::Elf::isElfMagic(bin)) {
8887
// Invalid binary.
89-
if (decryptedBin != nullptr) {
90-
delete[] decryptedBin;
91-
}
92-
buildLog_ += "Elf Magic failed";
93-
buildLog_ += "\n";
88+
delete[] decryptedBin;
89+
buildLog_ += "Elf Magic failed\n";
9490
return false;
9591
}
9692

0 commit comments

Comments
 (0)