[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));
_assert_(data_ != nullptr);
}
~FastVec() { if (data_) free(data_); }
~FastVec() { free(data_); }
T &push_uninitialized() {
if (size_ < capacity_) {

View File

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

View File

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

View File

@ -63,9 +63,7 @@ struct AutoCharArrayBuf {
buf_ = nullptr;
}
void reset(char *buf) {
if (buf_) {
delete[] buf_;
}
delete[] buf_;
buf_ = buf;
}
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.
std::lock_guard<std::mutex> 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_;

View File

@ -64,8 +64,7 @@ void DoClass(PointerWrap &p, T &x) {
template<class T>
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);

View File

@ -63,8 +63,7 @@ template<class K, class T>
void Do(PointerWrap &p, std::map<K, T *> &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<class K, class T>
void Do(PointerWrap &p, std::unordered_map<K, T *> &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<class K, class T>
void Do(PointerWrap &p, std::multimap<K, T *> &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<class K, class T>
void Do(PointerWrap &p, std::unordered_multimap<K, T *> &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;

View File

@ -55,8 +55,7 @@ template <class T>
void Do(PointerWrap &p, std::set<T *> &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);

View File

@ -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);
}

View File

@ -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);

View File

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

View File

@ -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);

View File

@ -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();

View File

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

View File

@ -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(); }

View File

@ -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<PSPModule>(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<PSPModule>(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<PSPModule>(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;

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
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);

View File

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

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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<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);
if(ptr) delete[] ptr;
delete[] ptr;
ptr = nullptr;
return false;
}

View File

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

View File

@ -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);

View File

@ -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;
}

View File

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