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
AssDialogueBlockOverride::~AssDialogueBlockOverride () {
for (std::vector<AssOverrideTag*>::iterator cur=Tags.begin();cur!=Tags.end();cur++) {
delete *cur;
for (size_t i=0;i<Tags.size();i++) {
delete Tags[i];
}
Tags.clear();
}
@ -99,6 +99,9 @@ AssDialogueBlockOverride::~AssDialogueBlockOverride () {
// Read tags
void AssDialogueBlockOverride::ParseTags () {
// Clear current vector
for (size_t i=0;i<Tags.size();i++) {
delete Tags[i];
}
Tags.clear();
// Fix parenthesis matching
@ -477,6 +480,13 @@ AssOverrideTag::AssOverrideTag () {
//////////////
// Destructor
AssOverrideTag::~AssOverrideTag () {
Clear();
}
/////////
// Clear
void AssOverrideTag::Clear() {
for (std::vector<AssOverrideParameter*>::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) {

View file

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

View file

@ -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();
}

View file

@ -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();
}

View file

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