Fixed some minor memory leaks, and failed to fix another.

Originally committed to SVN as r796.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-15 06:56:35 +00:00
parent e5ad6e4b60
commit a8abb99e6b
5 changed files with 34 additions and 7 deletions

View File

@ -88,8 +88,8 @@ AssDialogueBlockOverride::AssDialogueBlockOverride () {
////////////// //////////////
// Destructor // Destructor
AssDialogueBlockOverride::~AssDialogueBlockOverride () { AssDialogueBlockOverride::~AssDialogueBlockOverride () {
for (std::vector<AssOverrideTag*>::iterator cur=Tags.begin();cur!=Tags.end();cur++) { for (size_t i=0;i<Tags.size();i++) {
delete *cur; delete Tags[i];
} }
Tags.clear(); Tags.clear();
} }
@ -99,6 +99,9 @@ AssDialogueBlockOverride::~AssDialogueBlockOverride () {
// Read tags // Read tags
void AssDialogueBlockOverride::ParseTags () { void AssDialogueBlockOverride::ParseTags () {
// Clear current vector // Clear current vector
for (size_t i=0;i<Tags.size();i++) {
delete Tags[i];
}
Tags.clear(); Tags.clear();
// Fix parenthesis matching // Fix parenthesis matching
@ -477,6 +480,13 @@ AssOverrideTag::AssOverrideTag () {
////////////// //////////////
// Destructor // Destructor
AssOverrideTag::~AssOverrideTag () { AssOverrideTag::~AssOverrideTag () {
Clear();
}
/////////
// Clear
void AssOverrideTag::Clear() {
for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) { for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) {
delete *cur; delete *cur;
} }
@ -523,6 +533,9 @@ bool AssOverrideTag::IsValid() {
///////////////////// /////////////////////
// Parses parameters // Parses parameters
void AssOverrideTag::ParseParameters(wxString text) { 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 // text is all text following the name until the next \ or the end of the override block
// Tokenize text, attempting to find all parameters // Tokenize text, attempting to find all parameters
@ -567,7 +580,7 @@ void AssOverrideTag::ParseParameters(wxString text) {
work = text.SubString(start, i-1); work = text.SubString(start, i-1);
work.Trim(true).Trim(false); work.Trim(true).Trim(false);
paramList.Add(work); paramList.Add(work);
wxLogDebug(_T("Got parameter: %s"), work.c_str()); //wxLogDebug(_T("Got parameter: %s"), work.c_str());
} }
if (i+1 < textlen) { if (i+1 < textlen) {

View File

@ -99,6 +99,7 @@ public:
bool IsValid(); bool IsValid();
void ParseParameters(wxString text); void ParseParameters(wxString text);
void Clear();
void SetText(wxString text); void SetText(wxString text);
wxString ToString(); wxString ToString();
}; };

View File

@ -55,6 +55,7 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "auto4_base.h" #include "auto4_base.h"
#include "subtitle_format.h"
/////////////////// ///////////////////
@ -138,7 +139,9 @@ bool AegisubApp::OnInit() {
//////// ////////
// Exit // Exit
int AegisubApp::OnExit() { int AegisubApp::OnExit() {
SubtitleFormat::DestroyFormats();
Options.Clear(); Options.Clear();
delete global_scripts;
return wxApp::OnExit(); return wxApp::OnExit();
} }

View File

@ -1047,7 +1047,10 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
// Pick from dialog // Pick from dialog
//wxColour color = wxGetColourFromUser(this,startcolor); //wxColour color = wxGetColourFromUser(this,startcolor);
wxColour color = GetColorFromUser(((AegisubApp*)wxTheApp)->frame, 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 // Generate insert string
AssColor asscolor(color); AssColor asscolor(color);
@ -1058,7 +1061,10 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
if (isFont) { if (isFont) {
// Pick from dialog // Pick from dialog
wxFont font = wxGetFontFromUser(this,startfont); wxFont font = wxGetFontFromUser(this,startfont);
if (!font.Ok()) return; if (!font.Ok()) {
delete line;
return;
}
// Generate insert string // Generate insert string
nInserted = 0; 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); insert += _T("\\u") + wxString::Format(_T("%i"),font.GetUnderlined() ? 1 : 0);
nInserted++; nInserted++;
} }
if (insert.IsEmpty()) return; if (insert.IsEmpty()) {
delete line;
return;
}
} }
// Generic tag // Generic tag
@ -1176,7 +1185,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
// Commit changes and shift selection // Commit changes and shift selection
TextEdit->SetTextTo(line->Text); TextEdit->SetTextTo(line->Text);
line->ClearBlocks(); delete line;
TextEdit->SetSelectionU(selstart+shift,selend+shift); TextEdit->SetSelectionU(selstart+shift,selend+shift);
TextEdit->SetFocus(); TextEdit->SetFocus();
} }

View File

@ -636,6 +636,7 @@ int SubsTextEditCtrl::GetReverseUnicodePosition(int pos) {
// Convert back and return its length // Convert back and return its length
wxString buf3(buf2,wxConvUTF8); wxString buf3(buf2,wxConvUTF8);
delete[] buf2;
return buf3.Length(); return buf3.Length();
} }