Merge pull request #1469 from PCSX2/valgrind-memleak

Valgrind memleak
This commit is contained in:
Gregory Hainaut 2016-07-22 18:17:37 +02:00 committed by GitHub
commit 9182a287e2
13 changed files with 85 additions and 68 deletions

View File

@ -34,7 +34,7 @@ bool BlockdumpFileReader::DetectBlockdump(AsyncFileReader* reader)
reader->SetBlockSize(1);
char buf[4];
char buf[5] = {0};
reader->ReadSync(buf, 0, 4);
bool isbd = (strncmp(buf, "BDV2", 4) == 0);

View File

@ -66,7 +66,7 @@ int FlatFileReader::FinishRead(void)
int min_nr = 1;
int max_nr = 1;
struct io_event* events = new io_event[max_nr];
struct io_event events[max_nr];
int event = io_getevents(m_aio_context, min_nr, max_nr, events, NULL);
if (event < 1) {

View File

@ -52,6 +52,7 @@ CtrlRegisterList::CtrlRegisterList(wxWindow* parent, DebugInterface* _cpu)
category = 0;
maxBits = 128;
lastPc = 0xFFFFFFFF;
resolvePointerStrings = false;
for (int i = 0; i < cpu->getRegisterCategoryCount(); i++)
{
@ -80,6 +81,13 @@ CtrlRegisterList::CtrlRegisterList(wxWindow* parent, DebugInterface* _cpu)
SetScrollbars(1, rowHeight, actualSize.x, actualSize.y / rowHeight, 0, 0);
}
CtrlRegisterList::~CtrlRegisterList()
{
for (auto& regs : changedCategories)
delete[] regs;
}
wxSize CtrlRegisterList::getOptimalSize() const
{
int columnChars = 0;

View File

@ -23,6 +23,7 @@ class CtrlRegisterList: public wxScrolledWindow
{
public:
CtrlRegisterList(wxWindow* parent, DebugInterface* _cpu);
~CtrlRegisterList();
void mouseEvent(wxMouseEvent& evt);
void keydownEvent(wxKeyEvent& evt);

View File

@ -42,9 +42,10 @@ class BaseSavestateEntry
{
protected:
BaseSavestateEntry() {}
virtual ~BaseSavestateEntry() throw() {}
public:
virtual ~BaseSavestateEntry() throw() {}
virtual wxString GetFilename() const=0;
virtual void FreezeIn( pxInputStream& reader ) const=0;
virtual void FreezeOut( SaveStateBase& writer ) const=0;
@ -142,6 +143,8 @@ void PluginSavestateEntry::FreezeOut( SaveStateBase& writer ) const
class SavestateEntry_EmotionMemory : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_EmotionMemory() throw() {}
wxString GetFilename() const { return L"eeMemory.bin"; }
u8* GetDataPtr() const { return eeMem->Main; }
uint GetDataSize() const { return sizeof(eeMem->Main); }
@ -156,6 +159,8 @@ public:
class SavestateEntry_IopMemory : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_IopMemory() throw() {}
wxString GetFilename() const { return L"iopMemory.bin"; }
u8* GetDataPtr() const { return iopMem->Main; }
uint GetDataSize() const { return sizeof(iopMem->Main); }
@ -164,6 +169,8 @@ public:
class SavestateEntry_HwRegs : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_HwRegs() throw() {}
wxString GetFilename() const { return L"eeHwRegs.bin"; }
u8* GetDataPtr() const { return eeHw; }
uint GetDataSize() const { return sizeof(eeHw); }
@ -172,6 +179,8 @@ public:
class SavestateEntry_IopHwRegs : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_IopHwRegs() throw() {}
wxString GetFilename() const { return L"iopHwRegs.bin"; }
u8* GetDataPtr() const { return iopHw; }
uint GetDataSize() const { return sizeof(iopHw); }
@ -180,6 +189,8 @@ public:
class SavestateEntry_Scratchpad : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_Scratchpad() throw() {}
wxString GetFilename() const { return L"Scratchpad.bin"; }
u8* GetDataPtr() const { return eeMem->Scratch; }
uint GetDataSize() const { return sizeof(eeMem->Scratch); }
@ -188,6 +199,8 @@ public:
class SavestateEntry_VU0mem : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_VU0mem() throw() {}
wxString GetFilename() const { return L"vu0Memory.bin"; }
u8* GetDataPtr() const { return vuRegs[0].Mem; }
uint GetDataSize() const { return VU0_MEMSIZE; }
@ -196,6 +209,8 @@ public:
class SavestateEntry_VU1mem : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_VU1mem() throw() {}
wxString GetFilename() const { return L"vu1Memory.bin"; }
u8* GetDataPtr() const { return vuRegs[1].Mem; }
uint GetDataSize() const { return VU1_MEMSIZE; }
@ -204,6 +219,8 @@ public:
class SavestateEntry_VU0prog : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_VU0prog() throw() {}
wxString GetFilename() const { return L"vu0MicroMem.bin"; }
u8* GetDataPtr() const { return vuRegs[0].Micro; }
uint GetDataSize() const { return VU0_PROGSIZE; }
@ -212,6 +229,8 @@ public:
class SavestateEntry_VU1prog : public MemorySavestateEntry
{
public:
virtual ~SavestateEntry_VU1prog() throw() {}
wxString GetFilename() const { return L"vu1MicroMem.bin"; }
u8* GetDataPtr() const { return vuRegs[1].Micro; }
uint GetDataSize() const { return VU1_PROGSIZE; }
@ -227,42 +246,26 @@ public:
// 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*>
{
typedef ScopedAlloc<const BaseSavestateEntry*> _parent;
public:
SavestateEntryPack()
: _parent( NumSavestateEntries )
{
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[];
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_GS )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_PAD )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_SPU2 )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_CDVD )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_USB )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_FW )),
std::unique_ptr<BaseSavestateEntry>(new PluginSavestateEntry( PluginId_DEV9 ))
};
static const SavestateEntryPack SavestateEntries;
// 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
// CompressThread and the UnzipFromDisk events. (note that CompressThread locks the
@ -336,7 +339,7 @@ protected:
internals.SetDataSize( saveme.GetCurrentPos() - internals.GetDataIndex() );
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();
SavestateEntries[i]->FreezeOut( saveme );
@ -527,10 +530,10 @@ protected:
bool foundVersion = false;
//bool foundScreenshot = false;
//bool foundEntry[numSavestateEntries] = false;
//bool foundEntry[ArraySize(SavestateEntries)] = false;
std::unique_ptr<wxZipEntry> foundInternal;
std::unique_ptr<wxZipEntry> foundEntry[NumSavestateEntries];
std::unique_ptr<wxZipEntry> foundEntry[ArraySize(SavestateEntries)];
while(true)
{
@ -561,7 +564,7 @@ protected:
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)
{
@ -582,7 +585,7 @@ protected:
// Log any parts and pieces that are missing, and then generate an exception.
bool throwIt = false;
for (uint i=0; i<NumSavestateEntries; ++i)
for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{
if (foundEntry[i]) continue;
@ -604,7 +607,7 @@ protected:
GetCoreThread().Pause();
SysClearExecutionCache();
for (uint i=0; i<NumSavestateEntries; ++i)
for (uint i=0; i<ArraySize(SavestateEntries); ++i)
{
if (!foundEntry[i]) continue;

View File

@ -138,6 +138,10 @@ GSDeviceOGL::~GSDeviceOGL()
// Must be done after the destruction of all shader/program objects
delete m_shader;
m_shader = NULL;
// Purge any pending message to reduce noise in Valgrind (potential memory leak
// in Mesa driver that doesn't free internal buffer when the context is destroyed)
CheckDebugLog();
}
void GSDeviceOGL::GenerateProfilerData()

View File

@ -203,6 +203,7 @@ public:
FogColor_AREF = GSVector4::zero();
HalfTexel = GSVector4::zero();
WH = GSVector4::zero();
TA_Af = GSVector4::zero();
MinMax = GSVector4::zero();
MskFix = GSVector4i::zero();
TC_OH_TS = GSVector4::zero();

View File

@ -20,7 +20,7 @@
#include "GamepadConfiguration.h"
// Construtor of GamepadConfiguration
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxFrame(
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title

View File

@ -32,7 +32,7 @@
#include "keyboard.h"
#include "onepad.h"
class GamepadConfiguration : public wxFrame
class GamepadConfiguration : public wxDialog
{
wxPanel* m_pan_gamepad_config;
wxCheckBox *m_cb_rumble, *m_cb_hack_sixaxis_usb, *m_cb_hack_sixaxis_pressure;

View File

@ -20,7 +20,7 @@
#include "JoystickConfiguration.h"
// Construtor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent) : wxFrame(
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent) : wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title

View File

@ -32,7 +32,7 @@
#include "keyboard.h"
#include "onepad.h"
class JoystickConfiguration : public wxFrame
class JoystickConfiguration : public wxDialog
{
wxPanel* m_pan_joystick_config;
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,

View File

@ -20,7 +20,7 @@
#include "dialog.h"
// Construtor of Dialog
Dialog::Dialog() : wxFrame( NULL, // Parent
Dialog::Dialog() : wxDialog( NULL, // Parent
wxID_ANY, // ID
_T("OnePad configuration"), // Title
wxDefaultPosition, // Position
@ -320,21 +320,24 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
}
else if(bt_id == Gamepad_config) // If the button ID is equals to the Gamepad_config button ID
{
m_frm_gamepad_config = new GamepadConfiguration(gamepad_id, this);
m_frm_gamepad_config->InitGamepadConfiguration();
m_frm_gamepad_config->Show(true);
GamepadConfiguration gamepad_config(gamepad_id, this);
gamepad_config.InitGamepadConfiguration();
gamepad_config.ShowModal();
}
else if(bt_id == JoyL_config) // If the button ID is equals to the JoyL_config button ID
{
m_frm_joystick_config = new JoystickConfiguration(gamepad_id, true, this);
m_frm_joystick_config->InitJoystickConfiguration();
m_frm_joystick_config->Show(true);
JoystickConfiguration joystick_config(gamepad_id, true, this);
joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal();
}
else if(bt_id == JoyR_config) // If the button ID is equals to the JoyR_config button ID
{
m_frm_joystick_config = new JoystickConfiguration(gamepad_id, false, this);
m_frm_joystick_config->InitJoystickConfiguration();
m_frm_joystick_config->Show(true);
JoystickConfiguration joystick_config(gamepad_id, false, this);
joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal();
}
else if(bt_id == Set_all) // If the button ID is equals to the Set_all button ID
{
@ -696,7 +699,8 @@ void Dialog::repopulate()
// Main
void DisplayDialog()
{
Dialog* dialog = new Dialog();
dialog->InitDialog();
dialog->Show(true);
Dialog dialog;
dialog.InitDialog();
dialog.ShowModal();
}

View File

@ -63,7 +63,7 @@ enum gui_buttons {
#define DEFAULT_WIDTH 1000
#define DEFAULT_HEIGHT 740
class Dialog : public wxFrame
class Dialog : public wxDialog
{
// Panels
opPanel* m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box
@ -80,10 +80,6 @@ class Dialog : public wxFrame
// Map the key pressed with the feedback image id
std::map<u32,int> m_map_images[GAMEPAD_NUMBER];
// Frame
GamepadConfiguration* m_frm_gamepad_config; // Gamepad Configuration frame
JoystickConfiguration* m_frm_joystick_config; // Joystick Configuration frame
// methods
void config_key(int, int);
void clear_key(int, int);