Fix a smattering of memory leaks.

Originally committed to SVN as r4157.
This commit is contained in:
Thomas Goyne 2010-02-25 21:45:39 +00:00
parent 41be900efa
commit 0a8a495aea
7 changed files with 26 additions and 18 deletions

View file

@ -98,10 +98,8 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
file_cache.Seek(0); file_cache.Seek(0);
// Finish // Finish
if (!canceled) { progress->Destroy();
progress->Destroy(); if (canceled) {
}
else {
file_cache.Close(); file_cache.Close();
delete[] data; delete[] data;
throw wxString(_T("Audio loading cancelled by user")); throw wxString(_T("Audio loading cancelled by user"));

View file

@ -104,8 +104,8 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *source) {
} }
// Clean up progress // Clean up progress
if (!canceled) progress->Destroy(); progress->Destroy();
else { if (canceled) {
Clear(); Clear();
throw wxString(_T("Audio loading cancelled by user")); throw wxString(_T("Audio loading cancelled by user"));
} }

View file

@ -254,9 +254,9 @@ namespace Automation4 {
// load user script // load user script
LuaScriptReader script_reader(GetFilename()); LuaScriptReader script_reader(GetFilename());
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) { if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) {
wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8); wxString err(lua_tostring(L, -1), wxConvUTF8);
err->Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n")); err.Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err->wx_str(); throw err;
} }
_stackcheck.check_stack(1); _stackcheck.check_stack(1);
// and execute it // and execute it
@ -264,9 +264,9 @@ namespace Automation4 {
// don't thread this, as there's no point in it and it seems to break on wx 2.8.3, for some reason // don't thread this, as there's no point in it and it seems to break on wx 2.8.3, for some reason
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {
// error occurred, assumed to be on top of Lua stack // error occurred, assumed to be on top of Lua stack
wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8); wxString err(lua_tostring(L, -1), wxConvUTF8);
err->Prepend(_T("Error initialising Lua script \"") + GetPrettyFilename() + _T("\":\n\n")); err.Prepend(_T("Error initialising Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err->wx_str(); throw err;
} }
_stackcheck.check_stack(0); _stackcheck.check_stack(0);
lua_getglobal(L, "version"); lua_getglobal(L, "version");
@ -313,6 +313,12 @@ namespace Automation4 {
name = GetPrettyFilename(); name = GetPrettyFilename();
description = e; description = e;
} }
catch (const wxString& e) {
Destroy();
loaded = false;
name = GetPrettyFilename();
description = e;
}
catch (Script *s) { catch (Script *s) {
// Be sure to properly propagate any scripts throw // Be sure to properly propagate any scripts throw
throw s; throw s;

View file

@ -111,9 +111,9 @@ void DialogProgress::SetProgress(int cur,int max) {
else count++; else count++;
} }
wxCommandEvent* evt = new wxCommandEvent(wxEVT_PROGRESS_UPDATE,0); wxCommandEvent evt(wxEVT_PROGRESS_UPDATE,0);
evt->SetInt(value); evt.SetInt(value);
AddPendingEvent(*evt); AddPendingEvent(evt);
} }

View file

@ -746,8 +746,9 @@ void DialogStyleManager::PasteToCurrent() {
wxStringTokenizer st(data,_T('\n')); wxStringTokenizer st(data,_T('\n'));
while (st.HasMoreTokens()) { while (st.HasMoreTokens()) {
AssStyle *s = NULL;
try { try {
AssStyle *s = new AssStyle(st.GetNextToken().Trim(true)); s = new AssStyle(st.GetNextToken().Trim(true));
if (s->Valid) { if (s->Valid) {
while (AssFile::top->GetStyle(s->name) != NULL) while (AssFile::top->GetStyle(s->name) != NULL)
s->name = _T("Copy of ") + s->name; s->name = _T("Copy of ") + s->name;
@ -763,6 +764,7 @@ void DialogStyleManager::PasteToCurrent() {
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
catch (...) { catch (...) {
delete s;
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
@ -785,8 +787,9 @@ void DialogStyleManager::PasteToStorage() {
wxStringTokenizer st(data,_T('\n')); wxStringTokenizer st(data,_T('\n'));
while (st.HasMoreTokens()) { while (st.HasMoreTokens()) {
AssStyle *s = NULL;
try { try {
AssStyle *s = new AssStyle(st.GetNextToken().Trim(true)); s = new AssStyle(st.GetNextToken().Trim(true));
if (s->Valid) { if (s->Valid) {
while (Store.GetStyle(s->name) != NULL) while (Store.GetStyle(s->name) != NULL)
s->name = _T("Copy of ") + s->name; s->name = _T("Copy of ") + s->name;
@ -802,6 +805,7 @@ void DialogStyleManager::PasteToStorage() {
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }
catch(...) { catch(...) {
delete s;
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this); wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
} }

View file

@ -122,7 +122,6 @@ void MatroskaWrapper::Close() {
if (file) { if (file) {
mkv_Close(file); mkv_Close(file);
file = NULL; file = NULL;
fclose(input->fp);
delete input; delete input;
} }
keyFrames.Clear(); keyFrames.Clear();

View file

@ -65,6 +65,7 @@ class AssFile;
class MkvStdIO : public InputStream { class MkvStdIO : public InputStream {
public: public:
MkvStdIO(wxString filename); MkvStdIO(wxString filename);
~MkvStdIO() { if (fp) fclose(fp); }
/// DOCME /// DOCME
FILE *fp; FILE *fp;