From 3c66f149d3fac81cbaaf702eadf46e20bae3a36b Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Fri, 12 Apr 2024 14:44:40 +0300 Subject: [PATCH] [Common/Core/Windows] Removed excess check pointer before delete or free() --- Common/Data/Collections/FastVec.h | 2 +- Common/Data/Format/JSONReader.h | 3 +-- Common/GPU/OpenGL/GLRenderManager.h | 4 +--- Common/GPU/OpenGL/GLSLProgram.cpp | 4 +--- Common/Log/LogManager.cpp | 3 +-- Common/Serialize/SerializeFuncs.h | 3 +-- Common/Serialize/SerializeMap.h | 12 ++++-------- Common/Serialize/SerializeSet.h | 3 +-- Common/UI/Screen.cpp | 12 +++--------- Core/Dialog/SavedataParam.cpp | 10 ++++------ Core/ELF/ParamSFO.h | 3 +-- Core/Font/PGF.cpp | 8 ++------ Core/HLE/ThreadQueueList.h | 3 +-- Core/HLE/sceKernelInterrupt.cpp | 3 +-- Core/HLE/sceKernelMemory.cpp | 4 +--- Core/HLE/sceKernelModule.cpp | 16 +++++----------- Core/HLE/sceNetAdhoc.cpp | 2 +- Core/HLE/scePsmf.cpp | 3 +-- Core/HW/BufferQueue.h | 6 ++---- Core/HW/MediaEngine.cpp | 6 ++---- Core/HW/SasAudio.h | 2 +- Core/MIPS/MIPSVFPUUtils.cpp | 5 ++--- GPU/Vulkan/ShaderManagerVulkan.cpp | 3 +-- Windows/Debugger/CtrlRegisterList.cpp | 6 ++---- Windows/MainWindow.cpp | 12 ++++-------- Windows/RawInput.cpp | 4 +--- 26 files changed, 46 insertions(+), 96 deletions(-) diff --git a/Common/Data/Collections/FastVec.h b/Common/Data/Collections/FastVec.h index a8abb5e140..5bff743723 100644 --- a/Common/Data/Collections/FastVec.h +++ b/Common/Data/Collections/FastVec.h @@ -20,7 +20,7 @@ public: data_ = (T *)malloc(initialCapacity * sizeof(T)); _assert_(data_ != nullptr); } - ~FastVec() { if (data_) free(data_); } + ~FastVec() { free(data_); } T &push_uninitialized() { if (size_ < capacity_) { diff --git a/Common/Data/Format/JSONReader.h b/Common/Data/Format/JSONReader.h index 774f1c37c9..4cd849c52b 100644 --- a/Common/Data/Format/JSONReader.h +++ b/Common/Data/Format/JSONReader.h @@ -61,8 +61,7 @@ public: } ~JsonReader() { - if (buffer_) - free(buffer_); + free(buffer_); } bool ok() const { return ok_; } diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 558fd37879..f6e0132032 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -122,9 +122,7 @@ public: if (program) { glDeleteProgram(program); } - if (locData_) { - delete locData_; - } + delete locData_; } struct Semantic { int location; diff --git a/Common/GPU/OpenGL/GLSLProgram.cpp b/Common/GPU/OpenGL/GLSLProgram.cpp index ef71731323..c8c93dc0e9 100644 --- a/Common/GPU/OpenGL/GLSLProgram.cpp +++ b/Common/GPU/OpenGL/GLSLProgram.cpp @@ -63,9 +63,7 @@ struct AutoCharArrayBuf { buf_ = nullptr; } void reset(char *buf) { - if (buf_) { - delete[] buf_; - } + delete[] buf_; buf_ = buf; } operator char *() { diff --git a/Common/Log/LogManager.cpp b/Common/Log/LogManager.cpp index 5b85b7d8a0..b3eedf9f19 100644 --- a/Common/Log/LogManager.cpp +++ b/Common/Log/LogManager.cpp @@ -189,8 +189,7 @@ LogManager::~LogManager() { // Make sure we don't shutdown while logging. RemoveListener locks too, but there are gaps. std::lock_guard listeners_lock(listeners_lock_); - if (fileLog_) - delete fileLog_; + delete fileLog_; #if !defined(MOBILE_DEVICE) || defined(_DEBUG) #if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) delete consoleLog_; diff --git a/Common/Serialize/SerializeFuncs.h b/Common/Serialize/SerializeFuncs.h index 7e32c76f3f..88712d1c9b 100644 --- a/Common/Serialize/SerializeFuncs.h +++ b/Common/Serialize/SerializeFuncs.h @@ -64,8 +64,7 @@ void DoClass(PointerWrap &p, T &x) { template void DoClass(PointerWrap &p, T *&x) { if (p.mode == PointerWrap::MODE_READ) { - if (x != nullptr) - delete x; + delete x; x = new T(); } x->DoState(p); diff --git a/Common/Serialize/SerializeMap.h b/Common/Serialize/SerializeMap.h index 4e5619bdbe..641dd9bae7 100644 --- a/Common/Serialize/SerializeMap.h +++ b/Common/Serialize/SerializeMap.h @@ -63,8 +63,7 @@ template void Do(PointerWrap &p, std::map &x) { if (p.mode == PointerWrap::MODE_READ) { for (auto it = x.begin(), end = x.end(); it != end; ++it) { - if (it->second != nullptr) - delete it->second; + delete it->second; } } T *dv = nullptr; @@ -81,8 +80,7 @@ template void Do(PointerWrap &p, std::unordered_map &x) { if (p.mode == PointerWrap::MODE_READ) { for (auto it = x.begin(), end = x.end(); it != end; ++it) { - if (it->second != nullptr) - delete it->second; + delete it->second; } } T *dv = nullptr; @@ -135,8 +133,7 @@ template void Do(PointerWrap &p, std::multimap &x) { if (p.mode == PointerWrap::MODE_READ) { for (auto it = x.begin(), end = x.end(); it != end; ++it) { - if (it->second != nullptr) - delete it->second; + delete it->second; } } T *dv = nullptr; @@ -153,8 +150,7 @@ template void Do(PointerWrap &p, std::unordered_multimap &x) { if (p.mode == PointerWrap::MODE_READ) { for (auto it = x.begin(), end = x.end(); it != end; ++it) { - if (it->second != nullptr) - delete it->second; + delete it->second; } } T *dv = nullptr; diff --git a/Common/Serialize/SerializeSet.h b/Common/Serialize/SerializeSet.h index 642b0dc6bb..7917f51f52 100644 --- a/Common/Serialize/SerializeSet.h +++ b/Common/Serialize/SerializeSet.h @@ -55,8 +55,7 @@ template void Do(PointerWrap &p, std::set &x) { if (p.mode == PointerWrap::MODE_READ) { for (auto it = x.begin(), end = x.end(); it != end; ++it) { - if (*it != nullptr) - delete *it; + delete *it; } } DoSet(p, x); diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index 05a6c155c4..121702d4e4 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -96,9 +96,7 @@ void ScreenManager::switchToNext() { } stack_.push_back(nextStack_.front()); nextStack_.front().screen->focusChanged(ScreenFocusChange::FOCUS_BECAME_TOP); - if (temp.screen) { - delete temp.screen; - } + delete temp.screen; UI::SetFocusedView(nullptr); // When will this ever happen? Should handle focus here too? @@ -403,15 +401,11 @@ void ScreenManager::processFinishDialog() { } void ScreenManager::SetBackgroundOverlayScreens(Screen *backgroundScreen, Screen *overlayScreen) { - if (backgroundScreen_) { - delete backgroundScreen_; - } + delete backgroundScreen_; backgroundScreen_ = backgroundScreen; backgroundScreen_->setScreenManager(this); - if (overlayScreen_) { - delete overlayScreen_; - } + delete overlayScreen_; overlayScreen_ = overlayScreen; overlayScreen_->setScreenManager(this); } diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index a0cbad3996..bdb893cfe2 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -1494,16 +1494,15 @@ void SavedataParam::Clear() } delete [] saveDataList; - saveDataList = 0; + saveDataList = NULL; saveDataListCount = 0; } if (noSaveIcon) { - if (noSaveIcon->texture != NULL) - delete noSaveIcon->texture; + delete noSaveIcon->texture; noSaveIcon->texture = NULL; delete noSaveIcon; - noSaveIcon = 0; + noSaveIcon = NULL; } } @@ -1924,8 +1923,7 @@ void SavedataParam::DoState(PointerWrap &p) { Do(p, saveDataListCount); Do(p, saveNameListDataCount); if (p.mode == p.MODE_READ) { - if (saveDataList) - delete [] saveDataList; + delete [] saveDataList; if (saveDataListCount != 0) { saveDataList = new SaveFileInfo[saveDataListCount]; DoArray(p, saveDataList, saveDataListCount); diff --git a/Core/ELF/ParamSFO.h b/Core/ELF/ParamSFO.h index cb76cde4a6..0b675ea892 100644 --- a/Core/ELF/ParamSFO.h +++ b/Core/ELF/ParamSFO.h @@ -83,8 +83,7 @@ private: void SetData(const u8* data, int size); ~ValueData() { - if (u_value) - delete[] u_value; + delete[] u_value; } }; diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index e79bf18dfa..8edb182729 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -82,9 +82,7 @@ PGF::PGF() } PGF::~PGF() { - if (fontData) { - delete [] fontData; - } + delete [] fontData; } struct GlyphFromPGF1State { @@ -139,9 +137,7 @@ void PGF::DoState(PointerWrap &p) { Do(p, fontDataSizeTemp); fontDataSize = (size_t)fontDataSizeTemp; if (p.mode == p.MODE_READ) { - if (fontData) { - delete [] fontData; - } + delete [] fontData; if (fontDataSize) { fontData = new u8[fontDataSize]; DoArray(p, fontData, (int)fontDataSize); diff --git a/Core/HLE/ThreadQueueList.h b/Core/HLE/ThreadQueueList.h index 2e5e76c2c8..bccf6f7922 100644 --- a/Core/HLE/ThreadQueueList.h +++ b/Core/HLE/ThreadQueueList.h @@ -160,8 +160,7 @@ struct ThreadQueueList { inline void clear() { for (int i = 0; i < NUM_QUEUES; ++i) { - if (queues[i].data != nullptr) - free(queues[i].data); + free(queues[i].data); } memset(queues, 0, sizeof(queues)); first = invalid(); diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 5794150250..f20d183048 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -433,8 +433,7 @@ void __KernelReturnFromInterrupt() void __RegisterIntrHandler(u32 intrNumber, IntrHandler* handler) { - if(intrHandlers[intrNumber]) - delete intrHandlers[intrNumber]; + delete intrHandlers[intrNumber]; intrHandlers[intrNumber] = handler; } diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 98992800f4..36db220d6e 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -95,9 +95,7 @@ struct FPL : public KernelObject { FPL() : blocks(NULL), nextBlock(0) {} ~FPL() { - if (blocks != NULL) { - delete [] blocks; - } + delete [] blocks; } const char *GetName() override { return nf.name; } const char *GetTypeName() override { return GetStaticTypeName(); } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 03ddb4860d..f5c41ece3e 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1387,8 +1387,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load if (*magicPtr != 0x464c457f) { ERROR_LOG(Log::sceModule, "Wrong magic number %08x", *magicPtr); *error_string = "File corrupt"; - if (newptr) - delete [] newptr; + delete [] newptr; module->Cleanup(); kernelObjects.Destroy(module->GetUID()); error = SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE; @@ -1401,8 +1400,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load int result = reader.LoadInto(loadAddress, fromTop); if (result != SCE_KERNEL_ERROR_OK) { ERROR_LOG(Log::sceModule, "LoadInto failed with error %08x",result); - if (newptr) - delete [] newptr; + delete [] newptr; module->Cleanup(); kernelObjects.Destroy(module->GetUID()); error = result; @@ -1426,8 +1424,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load if (!Memory::IsValidAddress(modinfoaddr)) { *error_string = StringFromFormat("Bad module info address %08x", modinfoaddr); ERROR_LOG(Log::sceModule, "Bad module info address %08x", modinfoaddr); - if (newptr) - delete[] newptr; + delete[] newptr; module->Cleanup(); kernelObjects.Destroy(module->GetUID()); error = SCE_KERNEL_ERROR_BAD_FILE; // Probably not the right error code. @@ -1729,8 +1726,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load module->nm.entry_addr = -1; } - if (newptr) - delete [] newptr; + delete [] newptr; if (!reportedModule && IsHLEVersionedModule(modinfo->name)) { INFO_LOG(Log::sceModule, "Loading module %s with version %04x, devkit %08x", modinfo->name, modinfo->moduleVersion, devkitVersion); @@ -1817,9 +1813,7 @@ static PSPModule *__KernelLoadModule(u8 *fileptr, size_t fileSize, SceKernelLMOp u32 error; module = __KernelLoadELFFromPtr(temp ? temp : fileptr + offsets[5], elfSize, PSP_GetDefaultLoadAddress(), false, error_string, &magic, error); - if (temp) { - delete [] temp; - } + delete [] temp; } else if (fileSize > sizeof(PSP_Header)) { u32 error; u32 magic = 0; diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 9e6d45900a..e83b35d2f7 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -5008,7 +5008,7 @@ int NetAdhocMatching_Start(int matchingId, int evthPri, int evthPartitionId, int //sceNetAdhocMatchingSetHelloOpt(matchingId, optLen, optDataAddr); //SetHelloOpt only works when context is running if ((optLen > 0) && Memory::IsValidAddress(optDataAddr)) { // Allocate the memory and copy the content - if (item->hello != NULL) free(item->hello); + free(item->hello); item->hello = (uint8_t*)malloc(optLen); if (item->hello != NULL) { Memory::Memcpy(item->hello, optDataAddr, optLen); diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 19c0a481c9..1e08e9fbfd 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -219,8 +219,7 @@ public: PsmfPlayer(const PsmfPlayerCreateData *data); ~PsmfPlayer() { AbortFinish(); - if (mediaengine) - delete mediaengine; + delete mediaengine; pspFileSystem.CloseFile(filehandle); } void DoState(PointerWrap &p); diff --git a/Core/HW/BufferQueue.h b/Core/HW/BufferQueue.h index 6b950e9071..2bb4c8fb5b 100644 --- a/Core/HW/BufferQueue.h +++ b/Core/HW/BufferQueue.h @@ -29,14 +29,12 @@ struct BufferQueue { } ~BufferQueue() { - if (bufQueue) - delete [] bufQueue; + delete [] bufQueue; } bool alloc(int size) { _assert_(size > 0); - if (bufQueue) - delete [] bufQueue; + delete [] bufQueue; bufQueue = new unsigned char[size]; bufQueueSize = size; clear(); diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 8da752aed7..d7fb5388d0 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -147,10 +147,8 @@ MediaEngine::~MediaEngine() { void MediaEngine::closeMedia() { closeContext(); - if (m_pdata) - delete m_pdata; - if (m_demux) - delete m_demux; + delete m_pdata; + delete m_demux; m_pdata = nullptr; m_demux = nullptr; AudioClose(&m_audioContext); diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index 25dd008ba0..7cd5e094f1 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -138,7 +138,7 @@ private: class SasAtrac3 { public: SasAtrac3() : contextAddr_(0), atracID_(-1), sampleQueue_(0), end_(false) {} - ~SasAtrac3() { if (sampleQueue_) delete sampleQueue_; } + ~SasAtrac3() { delete sampleQueue_; } int setContext(u32 context); void getNextSamples(s16 *outbuf, int wantedSamples); int addStreamData(u32 bufPtr, u32 addbytes); diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 6e65702304..850278e650 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -1000,10 +1000,9 @@ static inline bool load_vfpu_table(T *&ptr, const char *filename, size_t expecte size_t size = 0u; INFO_LOG(Log::CPU, "Loading '%s'...", filename); ptr = reinterpret_cast(g_VFS.ReadFile(filename, &size)); - if(!ptr || size != expected_size) - { + if (!ptr || size != expected_size) { ERROR_LOG(Log::CPU, "Error loading '%s' (size=%u, expected: %u)", filename, (unsigned)size, (unsigned)expected_size); - if(ptr) delete[] ptr; + delete[] ptr; ptr = nullptr; return false; } diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index 10a8371768..649bbb5106 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -91,8 +91,7 @@ static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, #ifdef SHADERLOG OutputDebugStringA("OK"); #endif - if (tag) - delete tag; + delete tag; } return shaderModule; }; diff --git a/Windows/Debugger/CtrlRegisterList.cpp b/Windows/Debugger/CtrlRegisterList.cpp index 2a5bc7a6c2..8482ddb112 100644 --- a/Windows/Debugger/CtrlRegisterList.cpp +++ b/Windows/Debugger/CtrlRegisterList.cpp @@ -142,10 +142,8 @@ CtrlRegisterList::CtrlRegisterList(HWND _wnd) CtrlRegisterList::~CtrlRegisterList() { DeleteObject(font); - if (lastCat0Values != NULL) - delete [] lastCat0Values; - if (changedCat0Regs != NULL) - delete [] changedCat0Regs; + delete [] lastCat0Values; + delete [] changedCat0Regs; } void fillRect(HDC hdc, RECT *rect, COLORREF colour); diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 09857e31d2..ffffb557f4 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -583,25 +583,21 @@ namespace MainWindow void DestroyDebugWindows() { DialogManager::RemoveDlg(disasmWindow); - if (disasmWindow) - delete disasmWindow; + delete disasmWindow; disasmWindow = nullptr; #if PPSSPP_API(ANY_GL) DialogManager::RemoveDlg(geDebuggerWindow); - if (geDebuggerWindow) - delete geDebuggerWindow; + delete geDebuggerWindow; geDebuggerWindow = nullptr; #endif DialogManager::RemoveDlg(memoryWindow); - if (memoryWindow) - delete memoryWindow; + delete memoryWindow; memoryWindow = nullptr; DialogManager::RemoveDlg(vfpudlg); - if (vfpudlg) - delete vfpudlg; + delete vfpudlg; vfpudlg = nullptr; } diff --git a/Windows/RawInput.cpp b/Windows/RawInput.cpp index a8e7ceea01..0227675d48 100644 --- a/Windows/RawInput.cpp +++ b/Windows/RawInput.cpp @@ -443,9 +443,7 @@ namespace WindowsRawInput { } void Shutdown() { - if (rawInputBuffer) { - free(rawInputBuffer); - } + free(rawInputBuffer); rawInputBuffer = 0; } };