pcsx2 gui: fix a pseudo memory leak on SavestateEntryPack

It is a pseudo leak as it is a global object. Nevertheless it pollutes
the valgrind log.

v2:
* use an array of unique pointer
* use ArraySize instead of a constant
This commit is contained in:
Gregory Hainaut 2016-07-18 19:17:59 +02:00
parent e680a90e90
commit 11e5fe8879
1 changed files with 45 additions and 42 deletions

View File

@ -42,9 +42,10 @@ class BaseSavestateEntry
{ {
protected: protected:
BaseSavestateEntry() {} BaseSavestateEntry() {}
virtual ~BaseSavestateEntry() throw() {}
public: public:
virtual ~BaseSavestateEntry() throw() {}
virtual wxString GetFilename() const=0; virtual wxString GetFilename() const=0;
virtual void FreezeIn( pxInputStream& reader ) const=0; virtual void FreezeIn( pxInputStream& reader ) const=0;
virtual void FreezeOut( SaveStateBase& writer ) const=0; virtual void FreezeOut( SaveStateBase& writer ) const=0;
@ -142,6 +143,8 @@ void PluginSavestateEntry::FreezeOut( SaveStateBase& writer ) const
class SavestateEntry_EmotionMemory : public MemorySavestateEntry class SavestateEntry_EmotionMemory : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_EmotionMemory() throw() {}
wxString GetFilename() const { return L"eeMemory.bin"; } wxString GetFilename() const { return L"eeMemory.bin"; }
u8* GetDataPtr() const { return eeMem->Main; } u8* GetDataPtr() const { return eeMem->Main; }
uint GetDataSize() const { return sizeof(eeMem->Main); } uint GetDataSize() const { return sizeof(eeMem->Main); }
@ -156,6 +159,8 @@ public:
class SavestateEntry_IopMemory : public MemorySavestateEntry class SavestateEntry_IopMemory : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_IopMemory() throw() {}
wxString GetFilename() const { return L"iopMemory.bin"; } wxString GetFilename() const { return L"iopMemory.bin"; }
u8* GetDataPtr() const { return iopMem->Main; } u8* GetDataPtr() const { return iopMem->Main; }
uint GetDataSize() const { return sizeof(iopMem->Main); } uint GetDataSize() const { return sizeof(iopMem->Main); }
@ -164,6 +169,8 @@ public:
class SavestateEntry_HwRegs : public MemorySavestateEntry class SavestateEntry_HwRegs : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_HwRegs() throw() {}
wxString GetFilename() const { return L"eeHwRegs.bin"; } wxString GetFilename() const { return L"eeHwRegs.bin"; }
u8* GetDataPtr() const { return eeHw; } u8* GetDataPtr() const { return eeHw; }
uint GetDataSize() const { return sizeof(eeHw); } uint GetDataSize() const { return sizeof(eeHw); }
@ -172,6 +179,8 @@ public:
class SavestateEntry_IopHwRegs : public MemorySavestateEntry class SavestateEntry_IopHwRegs : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_IopHwRegs() throw() {}
wxString GetFilename() const { return L"iopHwRegs.bin"; } wxString GetFilename() const { return L"iopHwRegs.bin"; }
u8* GetDataPtr() const { return iopHw; } u8* GetDataPtr() const { return iopHw; }
uint GetDataSize() const { return sizeof(iopHw); } uint GetDataSize() const { return sizeof(iopHw); }
@ -180,6 +189,8 @@ public:
class SavestateEntry_Scratchpad : public MemorySavestateEntry class SavestateEntry_Scratchpad : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_Scratchpad() throw() {}
wxString GetFilename() const { return L"Scratchpad.bin"; } wxString GetFilename() const { return L"Scratchpad.bin"; }
u8* GetDataPtr() const { return eeMem->Scratch; } u8* GetDataPtr() const { return eeMem->Scratch; }
uint GetDataSize() const { return sizeof(eeMem->Scratch); } uint GetDataSize() const { return sizeof(eeMem->Scratch); }
@ -188,6 +199,8 @@ public:
class SavestateEntry_VU0mem : public MemorySavestateEntry class SavestateEntry_VU0mem : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_VU0mem() throw() {}
wxString GetFilename() const { return L"vu0Memory.bin"; } wxString GetFilename() const { return L"vu0Memory.bin"; }
u8* GetDataPtr() const { return vuRegs[0].Mem; } u8* GetDataPtr() const { return vuRegs[0].Mem; }
uint GetDataSize() const { return VU0_MEMSIZE; } uint GetDataSize() const { return VU0_MEMSIZE; }
@ -196,6 +209,8 @@ public:
class SavestateEntry_VU1mem : public MemorySavestateEntry class SavestateEntry_VU1mem : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_VU1mem() throw() {}
wxString GetFilename() const { return L"vu1Memory.bin"; } wxString GetFilename() const { return L"vu1Memory.bin"; }
u8* GetDataPtr() const { return vuRegs[1].Mem; } u8* GetDataPtr() const { return vuRegs[1].Mem; }
uint GetDataSize() const { return VU1_MEMSIZE; } uint GetDataSize() const { return VU1_MEMSIZE; }
@ -204,6 +219,8 @@ public:
class SavestateEntry_VU0prog : public MemorySavestateEntry class SavestateEntry_VU0prog : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_VU0prog() throw() {}
wxString GetFilename() const { return L"vu0MicroMem.bin"; } wxString GetFilename() const { return L"vu0MicroMem.bin"; }
u8* GetDataPtr() const { return vuRegs[0].Micro; } u8* GetDataPtr() const { return vuRegs[0].Micro; }
uint GetDataSize() const { return VU0_PROGSIZE; } uint GetDataSize() const { return VU0_PROGSIZE; }
@ -212,6 +229,8 @@ public:
class SavestateEntry_VU1prog : public MemorySavestateEntry class SavestateEntry_VU1prog : public MemorySavestateEntry
{ {
public: public:
virtual ~SavestateEntry_VU1prog() throw() {}
wxString GetFilename() const { return L"vu1MicroMem.bin"; } wxString GetFilename() const { return L"vu1MicroMem.bin"; }
u8* GetDataPtr() const { return vuRegs[1].Micro; } u8* GetDataPtr() const { return vuRegs[1].Micro; }
uint GetDataSize() const { return VU1_PROGSIZE; } uint GetDataSize() const { return VU1_PROGSIZE; }
@ -227,42 +246,26 @@ public:
// would not be useful). // would not be useful).
// //
static const uint NumSavestateEntries = 9 + PluginId_Count; static const std::unique_ptr<BaseSavestateEntry> SavestateEntries[] = {
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_EmotionMemory),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_IopMemory),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_HwRegs),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_IopHwRegs),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_Scratchpad),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_VU0mem),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_VU1mem),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_VU0prog),
std::unique_ptr<BaseSavestateEntry>(new SavestateEntry_VU1prog),
class SavestateEntryPack : public ScopedAlloc<const BaseSavestateEntry*> std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_GS )),
{ std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_PAD )),
typedef ScopedAlloc<const BaseSavestateEntry*> _parent; std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_SPU2 )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_CDVD )),
public: std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_USB )),
SavestateEntryPack() std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_FW )),
: _parent( NumSavestateEntries ) std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_DEV9 ))
{
uint i = 0; // more convenient in case we re-arrange anything...
this->operator[](i++) = new SavestateEntry_EmotionMemory;
this->operator[](i++) = new SavestateEntry_IopMemory;
this->operator[](i++) = new SavestateEntry_HwRegs;
this->operator[](i++) = new SavestateEntry_IopHwRegs;
this->operator[](i++) = new SavestateEntry_Scratchpad;
this->operator[](i++) = new SavestateEntry_VU0mem;
this->operator[](i++) = new SavestateEntry_VU1mem;
this->operator[](i++) = new SavestateEntry_VU0prog;
this->operator[](i++) = new SavestateEntry_VU1prog;
this->operator[](i++) = new PluginSavestateEntry( PluginId_GS );
this->operator[](i++) = new PluginSavestateEntry( PluginId_PAD );
this->operator[](i++) = new PluginSavestateEntry( PluginId_SPU2 );
this->operator[](i++) = new PluginSavestateEntry( PluginId_CDVD );
this->operator[](i++) = new PluginSavestateEntry( PluginId_USB );
this->operator[](i++) = new PluginSavestateEntry( PluginId_FW );
this->operator[](i++) = new PluginSavestateEntry( PluginId_DEV9 );
}
using _parent::operator[];
}; };
static const SavestateEntryPack SavestateEntries;
// It's bad mojo to have savestates trying to read and write from the same file at the // It's bad mojo to have savestates trying to read and write from the same file at the
// same time. To prevent that we use this mutex lock, which is used by both the // same time. To prevent that we use this mutex lock, which is used by both the
// CompressThread and the UnzipFromDisk events. (note that CompressThread locks the // CompressThread and the UnzipFromDisk events. (note that CompressThread locks the
@ -336,7 +339,7 @@ protected:
internals.SetDataSize( saveme.GetCurrentPos() - internals.GetDataIndex() ); internals.SetDataSize( saveme.GetCurrentPos() - internals.GetDataIndex() );
m_dest_list->Add( internals ); m_dest_list->Add( internals );
for (uint i=0; i<SavestateEntries.GetSize(); ++i) for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{ {
uint startpos = saveme.GetCurrentPos(); uint startpos = saveme.GetCurrentPos();
SavestateEntries[i]->FreezeOut( saveme ); SavestateEntries[i]->FreezeOut( saveme );
@ -527,10 +530,10 @@ protected:
bool foundVersion = false; bool foundVersion = false;
//bool foundScreenshot = false; //bool foundScreenshot = false;
//bool foundEntry[numSavestateEntries] = false; //bool foundEntry[ArraySize(SavestateEntries)] = false;
std::unique_ptr<wxZipEntry> foundInternal; std::unique_ptr<wxZipEntry> foundInternal;
std::unique_ptr<wxZipEntry> foundEntry[NumSavestateEntries]; std::unique_ptr<wxZipEntry> foundEntry[ArraySize(SavestateEntries)];
while(true) while(true)
{ {
@ -561,7 +564,7 @@ protected:
foundScreenshot = true; foundScreenshot = true;
}*/ }*/
for (uint i=0; i<NumSavestateEntries; ++i) for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{ {
if (entry->GetName().CmpNoCase(SavestateEntries[i]->GetFilename()) == 0) if (entry->GetName().CmpNoCase(SavestateEntries[i]->GetFilename()) == 0)
{ {
@ -582,7 +585,7 @@ protected:
// Log any parts and pieces that are missing, and then generate an exception. // Log any parts and pieces that are missing, and then generate an exception.
bool throwIt = false; bool throwIt = false;
for (uint i=0; i<NumSavestateEntries; ++i) for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{ {
if (foundEntry[i]) continue; if (foundEntry[i]) continue;
@ -604,7 +607,7 @@ protected:
GetCoreThread().Pause(); GetCoreThread().Pause();
SysClearExecutionCache(); SysClearExecutionCache();
for (uint i=0; i<NumSavestateEntries; ++i) for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{ {
if (!foundEntry[i]) continue; if (!foundEntry[i]) continue;