[Common/Core/Windows] Removed excess check pointer before delete or free()

This commit is contained in:
Herman Semenov 2024-04-12 14:44:40 +03:00 committed by Henrik Rydgård
parent 94f0e7afa8
commit 3c66f149d3
26 changed files with 46 additions and 96 deletions

View File

@ -20,7 +20,7 @@ public:
data_ = (T *)malloc(initialCapacity * sizeof(T)); data_ = (T *)malloc(initialCapacity * sizeof(T));
_assert_(data_ != nullptr); _assert_(data_ != nullptr);
} }
~FastVec() { if (data_) free(data_); } ~FastVec() { free(data_); }
T &push_uninitialized() { T &push_uninitialized() {
if (size_ < capacity_) { if (size_ < capacity_) {

View File

@ -61,8 +61,7 @@ public:
} }
~JsonReader() { ~JsonReader() {
if (buffer_) free(buffer_);
free(buffer_);
} }
bool ok() const { return ok_; } bool ok() const { return ok_; }

View File

@ -122,9 +122,7 @@ public:
if (program) { if (program) {
glDeleteProgram(program); glDeleteProgram(program);
} }
if (locData_) { delete locData_;
delete locData_;
}
} }
struct Semantic { struct Semantic {
int location; int location;

View File

@ -63,9 +63,7 @@ struct AutoCharArrayBuf {
buf_ = nullptr; buf_ = nullptr;
} }
void reset(char *buf) { void reset(char *buf) {
if (buf_) { delete[] buf_;
delete[] buf_;
}
buf_ = buf; buf_ = buf;
} }
operator char *() { operator char *() {

View File

@ -189,8 +189,7 @@ LogManager::~LogManager() {
// Make sure we don't shutdown while logging. RemoveListener locks too, but there are gaps. // Make sure we don't shutdown while logging. RemoveListener locks too, but there are gaps.
std::lock_guard<std::mutex> listeners_lock(listeners_lock_); std::lock_guard<std::mutex> listeners_lock(listeners_lock_);
if (fileLog_) delete fileLog_;
delete fileLog_;
#if !defined(MOBILE_DEVICE) || defined(_DEBUG) #if !defined(MOBILE_DEVICE) || defined(_DEBUG)
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) #if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
delete consoleLog_; delete consoleLog_;

View File

@ -64,8 +64,7 @@ void DoClass(PointerWrap &p, T &x) {
template<class T> template<class T>
void DoClass(PointerWrap &p, T *&x) { void DoClass(PointerWrap &p, T *&x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
if (x != nullptr) delete x;
delete x;
x = new T(); x = new T();
} }
x->DoState(p); x->DoState(p);

View File

@ -63,8 +63,7 @@ template<class K, class T>
void Do(PointerWrap &p, std::map<K, T *> &x) { void Do(PointerWrap &p, std::map<K, T *> &x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
for (auto it = x.begin(), end = x.end(); it != end; ++it) { for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (it->second != nullptr) delete it->second;
delete it->second;
} }
} }
T *dv = nullptr; T *dv = nullptr;
@ -81,8 +80,7 @@ template<class K, class T>
void Do(PointerWrap &p, std::unordered_map<K, T *> &x) { void Do(PointerWrap &p, std::unordered_map<K, T *> &x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
for (auto it = x.begin(), end = x.end(); it != end; ++it) { for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (it->second != nullptr) delete it->second;
delete it->second;
} }
} }
T *dv = nullptr; T *dv = nullptr;
@ -135,8 +133,7 @@ template<class K, class T>
void Do(PointerWrap &p, std::multimap<K, T *> &x) { void Do(PointerWrap &p, std::multimap<K, T *> &x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
for (auto it = x.begin(), end = x.end(); it != end; ++it) { for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (it->second != nullptr) delete it->second;
delete it->second;
} }
} }
T *dv = nullptr; T *dv = nullptr;
@ -153,8 +150,7 @@ template<class K, class T>
void Do(PointerWrap &p, std::unordered_multimap<K, T *> &x) { void Do(PointerWrap &p, std::unordered_multimap<K, T *> &x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
for (auto it = x.begin(), end = x.end(); it != end; ++it) { for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (it->second != nullptr) delete it->second;
delete it->second;
} }
} }
T *dv = nullptr; T *dv = nullptr;

View File

@ -55,8 +55,7 @@ template <class T>
void Do(PointerWrap &p, std::set<T *> &x) { void Do(PointerWrap &p, std::set<T *> &x) {
if (p.mode == PointerWrap::MODE_READ) { if (p.mode == PointerWrap::MODE_READ) {
for (auto it = x.begin(), end = x.end(); it != end; ++it) { for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (*it != nullptr) delete *it;
delete *it;
} }
} }
DoSet(p, x); DoSet(p, x);

View File

@ -96,9 +96,7 @@ void ScreenManager::switchToNext() {
} }
stack_.push_back(nextStack_.front()); stack_.push_back(nextStack_.front());
nextStack_.front().screen->focusChanged(ScreenFocusChange::FOCUS_BECAME_TOP); nextStack_.front().screen->focusChanged(ScreenFocusChange::FOCUS_BECAME_TOP);
if (temp.screen) { delete temp.screen;
delete temp.screen;
}
UI::SetFocusedView(nullptr); UI::SetFocusedView(nullptr);
// When will this ever happen? Should handle focus here too? // When will this ever happen? Should handle focus here too?
@ -403,15 +401,11 @@ void ScreenManager::processFinishDialog() {
} }
void ScreenManager::SetBackgroundOverlayScreens(Screen *backgroundScreen, Screen *overlayScreen) { void ScreenManager::SetBackgroundOverlayScreens(Screen *backgroundScreen, Screen *overlayScreen) {
if (backgroundScreen_) { delete backgroundScreen_;
delete backgroundScreen_;
}
backgroundScreen_ = backgroundScreen; backgroundScreen_ = backgroundScreen;
backgroundScreen_->setScreenManager(this); backgroundScreen_->setScreenManager(this);
if (overlayScreen_) { delete overlayScreen_;
delete overlayScreen_;
}
overlayScreen_ = overlayScreen; overlayScreen_ = overlayScreen;
overlayScreen_->setScreenManager(this); overlayScreen_->setScreenManager(this);
} }

View File

@ -1494,16 +1494,15 @@ void SavedataParam::Clear()
} }
delete [] saveDataList; delete [] saveDataList;
saveDataList = 0; saveDataList = NULL;
saveDataListCount = 0; saveDataListCount = 0;
} }
if (noSaveIcon) if (noSaveIcon)
{ {
if (noSaveIcon->texture != NULL) delete noSaveIcon->texture;
delete noSaveIcon->texture;
noSaveIcon->texture = NULL; noSaveIcon->texture = NULL;
delete noSaveIcon; delete noSaveIcon;
noSaveIcon = 0; noSaveIcon = NULL;
} }
} }
@ -1924,8 +1923,7 @@ void SavedataParam::DoState(PointerWrap &p) {
Do(p, saveDataListCount); Do(p, saveDataListCount);
Do(p, saveNameListDataCount); Do(p, saveNameListDataCount);
if (p.mode == p.MODE_READ) { if (p.mode == p.MODE_READ) {
if (saveDataList) delete [] saveDataList;
delete [] saveDataList;
if (saveDataListCount != 0) { if (saveDataListCount != 0) {
saveDataList = new SaveFileInfo[saveDataListCount]; saveDataList = new SaveFileInfo[saveDataListCount];
DoArray(p, saveDataList, saveDataListCount); DoArray(p, saveDataList, saveDataListCount);

View File

@ -83,8 +83,7 @@ private:
void SetData(const u8* data, int size); void SetData(const u8* data, int size);
~ValueData() { ~ValueData() {
if (u_value) delete[] u_value;
delete[] u_value;
} }
}; };

View File

@ -82,9 +82,7 @@ PGF::PGF()
} }
PGF::~PGF() { PGF::~PGF() {
if (fontData) { delete [] fontData;
delete [] fontData;
}
} }
struct GlyphFromPGF1State { struct GlyphFromPGF1State {
@ -139,9 +137,7 @@ void PGF::DoState(PointerWrap &p) {
Do(p, fontDataSizeTemp); Do(p, fontDataSizeTemp);
fontDataSize = (size_t)fontDataSizeTemp; fontDataSize = (size_t)fontDataSizeTemp;
if (p.mode == p.MODE_READ) { if (p.mode == p.MODE_READ) {
if (fontData) { delete [] fontData;
delete [] fontData;
}
if (fontDataSize) { if (fontDataSize) {
fontData = new u8[fontDataSize]; fontData = new u8[fontDataSize];
DoArray(p, fontData, (int)fontDataSize); DoArray(p, fontData, (int)fontDataSize);

View File

@ -160,8 +160,7 @@ struct ThreadQueueList {
inline void clear() { inline void clear() {
for (int i = 0; i < NUM_QUEUES; ++i) { 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)); memset(queues, 0, sizeof(queues));
first = invalid(); first = invalid();

View File

@ -433,8 +433,7 @@ void __KernelReturnFromInterrupt()
void __RegisterIntrHandler(u32 intrNumber, IntrHandler* handler) void __RegisterIntrHandler(u32 intrNumber, IntrHandler* handler)
{ {
if(intrHandlers[intrNumber]) delete intrHandlers[intrNumber];
delete intrHandlers[intrNumber];
intrHandlers[intrNumber] = handler; intrHandlers[intrNumber] = handler;
} }

View File

@ -95,9 +95,7 @@ struct FPL : public KernelObject
{ {
FPL() : blocks(NULL), nextBlock(0) {} FPL() : blocks(NULL), nextBlock(0) {}
~FPL() { ~FPL() {
if (blocks != NULL) { delete [] blocks;
delete [] blocks;
}
} }
const char *GetName() override { return nf.name; } const char *GetName() override { return nf.name; }
const char *GetTypeName() override { return GetStaticTypeName(); } const char *GetTypeName() override { return GetStaticTypeName(); }

View File

@ -1387,8 +1387,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load
if (*magicPtr != 0x464c457f) { if (*magicPtr != 0x464c457f) {
ERROR_LOG(Log::sceModule, "Wrong magic number %08x", *magicPtr); ERROR_LOG(Log::sceModule, "Wrong magic number %08x", *magicPtr);
*error_string = "File corrupt"; *error_string = "File corrupt";
if (newptr) delete [] newptr;
delete [] newptr;
module->Cleanup(); module->Cleanup();
kernelObjects.Destroy<PSPModule>(module->GetUID()); kernelObjects.Destroy<PSPModule>(module->GetUID());
error = SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE; 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); int result = reader.LoadInto(loadAddress, fromTop);
if (result != SCE_KERNEL_ERROR_OK) { if (result != SCE_KERNEL_ERROR_OK) {
ERROR_LOG(Log::sceModule, "LoadInto failed with error %08x",result); ERROR_LOG(Log::sceModule, "LoadInto failed with error %08x",result);
if (newptr) delete [] newptr;
delete [] newptr;
module->Cleanup(); module->Cleanup();
kernelObjects.Destroy<PSPModule>(module->GetUID()); kernelObjects.Destroy<PSPModule>(module->GetUID());
error = result; error = result;
@ -1426,8 +1424,7 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load
if (!Memory::IsValidAddress(modinfoaddr)) { if (!Memory::IsValidAddress(modinfoaddr)) {
*error_string = StringFromFormat("Bad module info address %08x", modinfoaddr); *error_string = StringFromFormat("Bad module info address %08x", modinfoaddr);
ERROR_LOG(Log::sceModule, "Bad module info address %08x", modinfoaddr); ERROR_LOG(Log::sceModule, "Bad module info address %08x", modinfoaddr);
if (newptr) delete[] newptr;
delete[] newptr;
module->Cleanup(); module->Cleanup();
kernelObjects.Destroy<PSPModule>(module->GetUID()); kernelObjects.Destroy<PSPModule>(module->GetUID());
error = SCE_KERNEL_ERROR_BAD_FILE; // Probably not the right error code. 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; module->nm.entry_addr = -1;
} }
if (newptr) delete [] newptr;
delete [] newptr;
if (!reportedModule && IsHLEVersionedModule(modinfo->name)) { if (!reportedModule && IsHLEVersionedModule(modinfo->name)) {
INFO_LOG(Log::sceModule, "Loading module %s with version %04x, devkit %08x", modinfo->name, modinfo->moduleVersion, devkitVersion); 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; u32 error;
module = __KernelLoadELFFromPtr(temp ? temp : fileptr + offsets[5], elfSize, PSP_GetDefaultLoadAddress(), false, error_string, &magic, 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)) { } else if (fileSize > sizeof(PSP_Header)) {
u32 error; u32 error;
u32 magic = 0; u32 magic = 0;

View File

@ -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 //sceNetAdhocMatchingSetHelloOpt(matchingId, optLen, optDataAddr); //SetHelloOpt only works when context is running
if ((optLen > 0) && Memory::IsValidAddress(optDataAddr)) { if ((optLen > 0) && Memory::IsValidAddress(optDataAddr)) {
// Allocate the memory and copy the content // Allocate the memory and copy the content
if (item->hello != NULL) free(item->hello); free(item->hello);
item->hello = (uint8_t*)malloc(optLen); item->hello = (uint8_t*)malloc(optLen);
if (item->hello != NULL) { if (item->hello != NULL) {
Memory::Memcpy(item->hello, optDataAddr, optLen); Memory::Memcpy(item->hello, optDataAddr, optLen);

View File

@ -219,8 +219,7 @@ public:
PsmfPlayer(const PsmfPlayerCreateData *data); PsmfPlayer(const PsmfPlayerCreateData *data);
~PsmfPlayer() { ~PsmfPlayer() {
AbortFinish(); AbortFinish();
if (mediaengine) delete mediaengine;
delete mediaengine;
pspFileSystem.CloseFile(filehandle); pspFileSystem.CloseFile(filehandle);
} }
void DoState(PointerWrap &p); void DoState(PointerWrap &p);

View File

@ -29,14 +29,12 @@ struct BufferQueue {
} }
~BufferQueue() { ~BufferQueue() {
if (bufQueue) delete [] bufQueue;
delete [] bufQueue;
} }
bool alloc(int size) { bool alloc(int size) {
_assert_(size > 0); _assert_(size > 0);
if (bufQueue) delete [] bufQueue;
delete [] bufQueue;
bufQueue = new unsigned char[size]; bufQueue = new unsigned char[size];
bufQueueSize = size; bufQueueSize = size;
clear(); clear();

View File

@ -147,10 +147,8 @@ MediaEngine::~MediaEngine() {
void MediaEngine::closeMedia() { void MediaEngine::closeMedia() {
closeContext(); closeContext();
if (m_pdata) delete m_pdata;
delete m_pdata; delete m_demux;
if (m_demux)
delete m_demux;
m_pdata = nullptr; m_pdata = nullptr;
m_demux = nullptr; m_demux = nullptr;
AudioClose(&m_audioContext); AudioClose(&m_audioContext);

View File

@ -138,7 +138,7 @@ private:
class SasAtrac3 { class SasAtrac3 {
public: public:
SasAtrac3() : contextAddr_(0), atracID_(-1), sampleQueue_(0), end_(false) {} SasAtrac3() : contextAddr_(0), atracID_(-1), sampleQueue_(0), end_(false) {}
~SasAtrac3() { if (sampleQueue_) delete sampleQueue_; } ~SasAtrac3() { delete sampleQueue_; }
int setContext(u32 context); int setContext(u32 context);
void getNextSamples(s16 *outbuf, int wantedSamples); void getNextSamples(s16 *outbuf, int wantedSamples);
int addStreamData(u32 bufPtr, u32 addbytes); int addStreamData(u32 bufPtr, u32 addbytes);

View File

@ -1000,10 +1000,9 @@ static inline bool load_vfpu_table(T *&ptr, const char *filename, size_t expecte
size_t size = 0u; size_t size = 0u;
INFO_LOG(Log::CPU, "Loading '%s'...", filename); INFO_LOG(Log::CPU, "Loading '%s'...", filename);
ptr = reinterpret_cast<decltype(&*ptr)>(g_VFS.ReadFile(filename, &size)); ptr = reinterpret_cast<decltype(&*ptr)>(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); 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; ptr = nullptr;
return false; return false;
} }

View File

@ -91,8 +91,7 @@ static Promise<VkShaderModule> *CompileShaderModuleAsync(VulkanContext *vulkan,
#ifdef SHADERLOG #ifdef SHADERLOG
OutputDebugStringA("OK"); OutputDebugStringA("OK");
#endif #endif
if (tag) delete tag;
delete tag;
} }
return shaderModule; return shaderModule;
}; };

View File

@ -142,10 +142,8 @@ CtrlRegisterList::CtrlRegisterList(HWND _wnd)
CtrlRegisterList::~CtrlRegisterList() CtrlRegisterList::~CtrlRegisterList()
{ {
DeleteObject(font); DeleteObject(font);
if (lastCat0Values != NULL) delete [] lastCat0Values;
delete [] lastCat0Values; delete [] changedCat0Regs;
if (changedCat0Regs != NULL)
delete [] changedCat0Regs;
} }
void fillRect(HDC hdc, RECT *rect, COLORREF colour); void fillRect(HDC hdc, RECT *rect, COLORREF colour);

View File

@ -583,25 +583,21 @@ namespace MainWindow
void DestroyDebugWindows() { void DestroyDebugWindows() {
DialogManager::RemoveDlg(disasmWindow); DialogManager::RemoveDlg(disasmWindow);
if (disasmWindow) delete disasmWindow;
delete disasmWindow;
disasmWindow = nullptr; disasmWindow = nullptr;
#if PPSSPP_API(ANY_GL) #if PPSSPP_API(ANY_GL)
DialogManager::RemoveDlg(geDebuggerWindow); DialogManager::RemoveDlg(geDebuggerWindow);
if (geDebuggerWindow) delete geDebuggerWindow;
delete geDebuggerWindow;
geDebuggerWindow = nullptr; geDebuggerWindow = nullptr;
#endif #endif
DialogManager::RemoveDlg(memoryWindow); DialogManager::RemoveDlg(memoryWindow);
if (memoryWindow) delete memoryWindow;
delete memoryWindow;
memoryWindow = nullptr; memoryWindow = nullptr;
DialogManager::RemoveDlg(vfpudlg); DialogManager::RemoveDlg(vfpudlg);
if (vfpudlg) delete vfpudlg;
delete vfpudlg;
vfpudlg = nullptr; vfpudlg = nullptr;
} }

View File

@ -443,9 +443,7 @@ namespace WindowsRawInput {
} }
void Shutdown() { void Shutdown() {
if (rawInputBuffer) { free(rawInputBuffer);
free(rawInputBuffer);
}
rawInputBuffer = 0; rawInputBuffer = 0;
} }
}; };