From a8abb99e6ba1c69733c224edb3deb44091054cea Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 15 Jan 2007 06:56:35 +0000 Subject: [PATCH] Fixed some minor memory leaks, and failed to fix another. Originally committed to SVN as r796. --- aegisub/ass_override.cpp | 19 ++++++++++++++++--- aegisub/ass_override.h | 1 + aegisub/main.cpp | 3 +++ aegisub/subs_edit_box.cpp | 17 +++++++++++++---- aegisub/subs_edit_ctrl.cpp | 1 + 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/aegisub/ass_override.cpp b/aegisub/ass_override.cpp index 1a47f5f31..d2be87fdd 100644 --- a/aegisub/ass_override.cpp +++ b/aegisub/ass_override.cpp @@ -88,8 +88,8 @@ AssDialogueBlockOverride::AssDialogueBlockOverride () { ////////////// // Destructor AssDialogueBlockOverride::~AssDialogueBlockOverride () { - for (std::vector::iterator cur=Tags.begin();cur!=Tags.end();cur++) { - delete *cur; + for (size_t i=0;i::iterator cur=Params.begin();cur!=Params.end();cur++) { delete *cur; } @@ -523,6 +533,9 @@ bool AssOverrideTag::IsValid() { ///////////////////// // Parses parameters void AssOverrideTag::ParseParameters(wxString text) { + // Clear first + Clear(); + // text is all text following the name until the next \ or the end of the override block // Tokenize text, attempting to find all parameters @@ -567,7 +580,7 @@ void AssOverrideTag::ParseParameters(wxString text) { work = text.SubString(start, i-1); work.Trim(true).Trim(false); paramList.Add(work); - wxLogDebug(_T("Got parameter: %s"), work.c_str()); + //wxLogDebug(_T("Got parameter: %s"), work.c_str()); } if (i+1 < textlen) { diff --git a/aegisub/ass_override.h b/aegisub/ass_override.h index e955a4e97..5e6a1ada8 100644 --- a/aegisub/ass_override.h +++ b/aegisub/ass_override.h @@ -99,6 +99,7 @@ public: bool IsValid(); void ParseParameters(wxString text); + void Clear(); void SetText(wxString text); wxString ToString(); }; diff --git a/aegisub/main.cpp b/aegisub/main.cpp index c9ce86a0f..a13553c2a 100644 --- a/aegisub/main.cpp +++ b/aegisub/main.cpp @@ -55,6 +55,7 @@ #include "ass_dialogue.h" #include "subs_grid.h" #include "auto4_base.h" +#include "subtitle_format.h" /////////////////// @@ -138,7 +139,9 @@ bool AegisubApp::OnInit() { //////// // Exit int AegisubApp::OnExit() { + SubtitleFormat::DestroyFormats(); Options.Clear(); + delete global_scripts; return wxApp::OnExit(); } diff --git a/aegisub/subs_edit_box.cpp b/aegisub/subs_edit_box.cpp index 79a8cb88e..bec9a9718 100644 --- a/aegisub/subs_edit_box.cpp +++ b/aegisub/subs_edit_box.cpp @@ -1047,7 +1047,10 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos) // Pick from dialog //wxColour color = wxGetColourFromUser(this,startcolor); wxColour color = GetColorFromUser(((AegisubApp*)wxTheApp)->frame, startcolor); - if (!color.Ok() || color == startcolor) return; + if (!color.Ok() || color == startcolor) { + delete line; + return; + } // Generate insert string AssColor asscolor(color); @@ -1058,7 +1061,10 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos) if (isFont) { // Pick from dialog wxFont font = wxGetFontFromUser(this,startfont); - if (!font.Ok()) return; + if (!font.Ok()) { + delete line; + return; + } // Generate insert string nInserted = 0; @@ -1082,7 +1088,10 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos) insert += _T("\\u") + wxString::Format(_T("%i"),font.GetUnderlined() ? 1 : 0); nInserted++; } - if (insert.IsEmpty()) return; + if (insert.IsEmpty()) { + delete line; + return; + } } // Generic tag @@ -1176,7 +1185,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos) // Commit changes and shift selection TextEdit->SetTextTo(line->Text); - line->ClearBlocks(); + delete line; TextEdit->SetSelectionU(selstart+shift,selend+shift); TextEdit->SetFocus(); } diff --git a/aegisub/subs_edit_ctrl.cpp b/aegisub/subs_edit_ctrl.cpp index 7dd5679a7..001b08df0 100644 --- a/aegisub/subs_edit_ctrl.cpp +++ b/aegisub/subs_edit_ctrl.cpp @@ -636,6 +636,7 @@ int SubsTextEditCtrl::GetReverseUnicodePosition(int pos) { // Convert back and return its length wxString buf3(buf2,wxConvUTF8); + delete[] buf2; return buf3.Length(); }