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);
// Finish
if (!canceled) {
progress->Destroy();
}
else {
progress->Destroy();
if (canceled) {
file_cache.Close();
delete[] data;
throw wxString(_T("Audio loading cancelled by user"));

View file

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

View file

@ -254,9 +254,9 @@ namespace Automation4 {
// load user script
LuaScriptReader script_reader(GetFilename());
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) {
wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8);
err->Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err->wx_str();
wxString err(lua_tostring(L, -1), wxConvUTF8);
err.Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err;
}
_stackcheck.check_stack(1);
// 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
if (lua_pcall(L, 0, 0, 0)) {
// error occurred, assumed to be on top of Lua stack
wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8);
err->Prepend(_T("Error initialising Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err->wx_str();
wxString err(lua_tostring(L, -1), wxConvUTF8);
err.Prepend(_T("Error initialising Lua script \"") + GetPrettyFilename() + _T("\":\n\n"));
throw err;
}
_stackcheck.check_stack(0);
lua_getglobal(L, "version");
@ -313,6 +313,12 @@ namespace Automation4 {
name = GetPrettyFilename();
description = e;
}
catch (const wxString& e) {
Destroy();
loaded = false;
name = GetPrettyFilename();
description = e;
}
catch (Script *s) {
// Be sure to properly propagate any scripts throw
throw s;

View file

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

View file

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

View file

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

View file

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