summaryrefslogtreecommitdiff
path: root/sw/source/uibase/misc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-09-14 15:13:03 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-09-15 14:34:41 +0200
commit8629850eb98ec7f3501f0904063958d61b370747 (patch)
tree11644d5006d28338948250cb1adaa0f5493f6ee5 /sw/source/uibase/misc
parent4e59ef9864cc659e7f5560648ed800c3575f805a (diff)
loplugin:useuniqueptr pass SwTextBlocks around by unique_ptr
fix leaks in SwGlossaryHdl::NewGlossary and SwGlossaryHdl::DelGlossary and SwGlossaryHdl::InsertGlossary error paths Change-Id: Iaf98fea08cd44bf68885e053854cf65372fcfc2c Reviewed-on: https://gerrit.libreoffice.org/60495 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/uibase/misc')
-rw-r--r--sw/source/uibase/misc/glosdoc.cxx14
-rw-r--r--sw/source/uibase/misc/glshell.cxx3
2 files changed, 7 insertions, 10 deletions
diff --git a/sw/source/uibase/misc/glosdoc.cxx b/sw/source/uibase/misc/glosdoc.cxx
index b2037bc4e61b..c0d17e3cc95e 100644
--- a/sw/source/uibase/misc/glosdoc.cxx
+++ b/sw/source/uibase/misc/glosdoc.cxx
@@ -145,17 +145,16 @@ OUString SwGlossaries::GetGroupTitle( const OUString& rGroupName )
OUString sGroup(rGroupName);
if (sGroup.indexOf(GLOS_DELIM)<0)
FindGroupName(sGroup);
- SwTextBlocks* pGroup = GetGroupDoc(sGroup);
+ std::unique_ptr<SwTextBlocks> pGroup = GetGroupDoc(sGroup);
if(pGroup)
{
sRet = pGroup->GetName();
- delete pGroup;
}
return sRet;
}
// supplies the group rName's text block document
-SwTextBlocks* SwGlossaries::GetGroupDoc(const OUString &rName,
+std::unique_ptr<SwTextBlocks> SwGlossaries::GetGroupDoc(const OUString &rName,
bool bCreate)
{
// insert to the list of text blocks if applicable
@@ -186,12 +185,11 @@ bool SwGlossaries::NewGroupDoc(OUString& rGroupName, const OUString& rTitle)
const OUString sNewFilePath(m_PathArr[nNewPath]);
const OUString sNewGroup = lcl_CheckFileName(sNewFilePath, rGroupName.getToken(0, GLOS_DELIM))
+ OUStringLiteral1(GLOS_DELIM) + sNewPath;
- SwTextBlocks *pBlock = GetGlosDoc( sNewGroup );
+ std::unique_ptr<SwTextBlocks> pBlock = GetGlosDoc( sNewGroup );
if(pBlock)
{
GetNameList().push_back(sNewGroup);
pBlock->SetName(rTitle);
- delete pBlock;
rGroupName = sNewGroup;
return true;
}
@@ -273,10 +271,10 @@ SwGlossaries::~SwGlossaries()
}
// read a block document
-SwTextBlocks* SwGlossaries::GetGlosDoc( const OUString &rName, bool bCreate ) const
+std::unique_ptr<SwTextBlocks> SwGlossaries::GetGlosDoc( const OUString &rName, bool bCreate ) const
{
sal_uInt16 nPath = static_cast<sal_uInt16>(rName.getToken(1, GLOS_DELIM).toInt32());
- SwTextBlocks *pTmp = nullptr;
+ std::unique_ptr<SwTextBlocks> pTmp;
if (static_cast<size_t>(nPath) < m_PathArr.size())
{
const OUString sFileURL =
@@ -288,7 +286,7 @@ SwTextBlocks* SwGlossaries::GetGlosDoc( const OUString &rName, bool bCreate ) co
if (bCreate || bExist)
{
- pTmp = new SwTextBlocks( sFileURL );
+ pTmp.reset(new SwTextBlocks( sFileURL ));
bool bOk = true;
if( pTmp->GetError() )
{
diff --git a/sw/source/uibase/misc/glshell.cxx b/sw/source/uibase/misc/glshell.cxx
index 6a0cca3eb80c..fa953c925093 100644
--- a/sw/source/uibase/misc/glshell.cxx
+++ b/sw/source/uibase/misc/glshell.cxx
@@ -201,7 +201,7 @@ SwDocShellRef SwGlossaries::EditGroupDoc( const OUString& rGroup, const OUString
{
SwDocShellRef xDocSh;
- SwTextBlocks* pGroup = GetGroupDoc( rGroup );
+ std::unique_ptr<SwTextBlocks> pGroup = GetGroupDoc( rGroup );
if (pGroup && pGroup->GetCount())
{
// query which view is registered. In WebWriter there is no normal view
@@ -268,7 +268,6 @@ SwDocShellRef SwGlossaries::EditGroupDoc( const OUString& rGroup, const OUString
if ( bShow )
pFrame->GetFrame().Appear();
}
- delete pGroup;
return xDocSh;
}