diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-01-21 18:23:20 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-01-21 22:13:31 +0100 |
commit | 535260983dd16c0e6621d206b5f5d0e30da33209 (patch) | |
tree | 90543e231b80a68eef350fe0bcb69053d5820cbf /sw | |
parent | 2e4bb77c1979ee893a7e969278639093e3f6aa8e (diff) |
SwGlossaryGroupDlg: fix memory leaks
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/ui/inc/glosbib.hxx | 6 | ||||
-rw-r--r-- | sw/source/ui/misc/glosbib.cxx | 102 |
2 files changed, 44 insertions, 64 deletions
diff --git a/sw/source/ui/inc/glosbib.hxx b/sw/source/ui/inc/glosbib.hxx index 83c270605ca3..9d955caa577b 100644 --- a/sw/source/ui/inc/glosbib.hxx +++ b/sw/source/ui/inc/glosbib.hxx @@ -83,9 +83,9 @@ class SwGlossaryGroupDlg : public SvxStandardDialog PushButton aDelPB; PushButton aRenamePB; - std::vector<String*> *pRemovedArr; - std::vector<String*> *pInsertedArr; - std::vector<String*> *pRenamedArr; + std::vector<String> m_RemovedArr; + std::vector<String> m_InsertedArr; + std::vector<String> m_RenamedArr; SwGlossaryHdl *pGlosHdl; diff --git a/sw/source/ui/misc/glosbib.cxx b/sw/source/ui/misc/glosbib.cxx index fff2a2c2ecaf..8de9c8f00573 100644 --- a/sw/source/ui/misc/glosbib.cxx +++ b/sw/source/ui/misc/glosbib.cxx @@ -75,9 +75,6 @@ SwGlossaryGroupDlg::SwGlossaryGroupDlg(Window * pParent, aDelPB( this, SW_RES(PB_DELETE)), aRenamePB( this, SW_RES(PB_RENAME)), - pRemovedArr(0), - pInsertedArr(0), - pRenamedArr(0), pGlosHdl(pHdl) { FreeResource(); @@ -139,26 +136,6 @@ SwGlossaryGroupDlg::SwGlossaryGroupDlg(Window * pParent, SwGlossaryGroupDlg::~SwGlossaryGroupDlg() { - - if(pInsertedArr) - { - for(std::vector<String*>::const_iterator it(pInsertedArr->begin()); it != pInsertedArr->end(); ++it) - delete *it; - delete pInsertedArr; - } - if(pRemovedArr) - { - for(std::vector<String*>::const_iterator it(pRemovedArr->begin()); it != pRemovedArr->end(); ++it) - delete *it; - delete pRemovedArr; - } - if(pRenamedArr) - { - for(std::vector<String*>::const_iterator it(pRenamedArr->begin()); it != pRenamedArr->end(); ++it) - delete *it; - delete pRenamedArr; - } - } void SwGlossaryGroupDlg::Apply() @@ -168,11 +145,12 @@ void SwGlossaryGroupDlg::Apply() String aActGroup = SwGlossaryDlg::GetCurrGroup(); - if(pRemovedArr) + if (!m_RemovedArr.empty()) { - for(std::vector<String*>::const_iterator it(pRemovedArr->begin()); it != pRemovedArr->end(); ++it) + for (std::vector<String>::const_iterator it(m_RemovedArr.begin()); + it != m_RemovedArr.end(); ++it) { - const String sDelGroup = (*it)->GetToken(0, '\t'); + const String sDelGroup = it->GetToken(0, '\t'); if( sDelGroup == aActGroup ) { //when the current group is deleted, the current group has to be relocated @@ -184,7 +162,7 @@ void SwGlossaryGroupDlg::Apply() } } String sMsg(SW_RES(STR_QUERY_DELETE_GROUP1)); - String sTitle( (*it)->GetToken(1, '\t') ); + String sTitle( it->GetToken(1, '\t') ); if(sTitle.Len()) sMsg += sTitle; else @@ -197,24 +175,28 @@ void SwGlossaryGroupDlg::Apply() } //don't rename before there was one - if(pRenamedArr) + if (!m_RenamedArr.empty()) { - for(std::vector<String*>::const_iterator it(pRenamedArr->begin()); it != pRenamedArr->end(); ++it) + for (std::vector<String>::const_iterator it(m_RenamedArr.begin()); + it != m_RenamedArr.end(); ++it) { xub_StrLen nStrSttPos = 0; - String sOld( (*it)->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos ) ); - String sNew( (*it)->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) ); - String sTitle( (*it)->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) ); + String sOld( it->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos ) ); + String sNew( it->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) ); + String sTitle( it->GetToken(0, RENAME_TOKEN_DELIM, nStrSttPos) ); pGlosHdl->RenameGroup(sOld, sNew, sTitle); - if( it == pRenamedArr->begin() ) + if (it == m_RenamedArr.begin()) + { sCreatedGroup = sNew; + } } } - if(pInsertedArr) + if (!m_InsertedArr.empty()) { - for(std::vector<String*>::const_iterator it(pInsertedArr->begin()); it != pInsertedArr->end(); ++it) + for (std::vector<String>::const_iterator it(m_InsertedArr.begin()); + it != m_InsertedArr.end(); ++it) { - String sNewGroup = **it; + String sNewGroup = *it; String sNewTitle = sNewGroup.GetToken(0, GLOS_DELIM); if( sNewGroup != aActGroup ) { @@ -257,9 +239,7 @@ IMPL_LINK( SwGlossaryGroupDlg, NewHdl, Button*, EMPTYARG ) sGroup += GLOS_DELIM; sGroup += String::CreateFromInt32(aPathLB.GetSelectEntryPos()); OSL_ENSURE(!pGlosHdl->FindGroupName(sGroup), "group already available!"); - if(!pInsertedArr) - pInsertedArr = new std::vector<String*>; - pInsertedArr->push_back(new String(sGroup)); + m_InsertedArr.push_back(sGroup); String sTemp(aNameED.GetText()); sTemp += '\t'; sTemp += aPathLB.GetSelectEntry(); @@ -288,13 +268,14 @@ IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton ) String sEntry(pUserData->sGroupName); // if the name to be deleted is among the new ones - get rid of it sal_Bool bDelete = sal_True; - if(pInsertedArr) + if (!m_InsertedArr.empty()) { - for(std::vector<String*>::iterator it(pInsertedArr->begin()); it != pInsertedArr->end(); ++it) + for (std::vector<String>::iterator it(m_InsertedArr.begin()); + it != m_InsertedArr.end(); ++it) { - if( **it == sEntry ) + if( *it == sEntry ) { - pInsertedArr->erase(it); + m_InsertedArr.erase(it); bDelete = sal_False; break; } @@ -304,13 +285,14 @@ IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton ) // it should probably be renamed? if(bDelete) { - if(pRenamedArr) + if (!m_RenamedArr.empty()) { - for(std::vector<String*>::iterator it(pRenamedArr->begin()); it != pRenamedArr->end(); ++it) + for (std::vector<String>::iterator it(m_RenamedArr.begin()); + it != m_RenamedArr.end(); ++it) { - if( (*it)->GetToken(0, RENAME_TOKEN_DELIM) == sEntry ) + if (it->GetToken(0, RENAME_TOKEN_DELIM) == sEntry) { - pRenamedArr->erase(it); + m_RenamedArr.erase(it); bDelete = sal_False; break; } @@ -319,12 +301,10 @@ IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton ) } if(bDelete) { - if(!pRemovedArr) - pRemovedArr = new std::vector<String*>; String sGroupEntry(pUserData->sGroupName); sGroupEntry += '\t'; sGroupEntry += pUserData->sGroupTitle; - pRemovedArr->push_back(new String(sGroupEntry)); + m_RemovedArr.push_back(sGroupEntry); } delete pUserData; aGroupTLB.GetModel()->Remove(pEntry); @@ -351,14 +331,15 @@ IMPL_LINK( SwGlossaryGroupDlg, RenameHdl, Button *, EMPTYARG ) // if the name to be renamed is among the new ones - replace sal_Bool bDone = sal_False; - if(pInsertedArr) + if (!m_InsertedArr.empty()) { - for(std::vector<String*>::iterator it(pInsertedArr->begin()); it != pInsertedArr->end(); ++it) + for (std::vector<String>::iterator it(m_InsertedArr.begin()); + it != m_InsertedArr.end(); ++it) { - if( **it == sEntry ) + if (*it == sEntry) { - pInsertedArr->erase(it); - pInsertedArr->push_back(new String(sNewName)); + m_InsertedArr.erase(it); + m_InsertedArr.push_back(sNewName); bDone = sal_True; break; } @@ -366,13 +347,11 @@ IMPL_LINK( SwGlossaryGroupDlg, RenameHdl, Button *, EMPTYARG ) } if(!bDone) { - if(!pRenamedArr) - pRenamedArr = new std::vector<String*>; sEntry += RENAME_TOKEN_DELIM; sEntry += sNewName; sEntry += RENAME_TOKEN_DELIM; sEntry += sNewTitle; - pRenamedArr->push_back(new String(sEntry)); + m_RenamedArr.push_back(sEntry); } delete (GlosBibUserData*)pEntry->GetUserData(); aGroupTLB.GetModel()->Remove(pEntry); @@ -454,11 +433,12 @@ sal_Bool SwGlossaryGroupDlg::IsDeleteAllowed(const String &rGroup) // as well! Because for non existing region names ReadOnly issues // sal_True. - if(pInsertedArr) + if (!m_InsertedArr.empty()) { - for(std::vector<String*>::const_iterator it(pInsertedArr->begin()); it != pInsertedArr->end(); ++it) + for (std::vector<String>::const_iterator it(m_InsertedArr.begin()); + it != m_InsertedArr.end(); ++it) { - if( **it == rGroup ) + if (*it == rGroup) { bDel = sal_True; break; |