[Libreoffice-commits] core.git: 2 commits - sfx2/inc sfx2/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Mon May 31 17:53:53 UTC 2021
sfx2/inc/autoredactdialog.hxx | 4 +--
sfx2/source/doc/autoredactdialog.cxx | 36 ++++++++++++++---------------------
sfx2/source/doc/doctemplates.cxx | 16 +++++++--------
3 files changed, 25 insertions(+), 31 deletions(-)
New commits:
commit af83bf98b2ea907437edf964cf7af50a5bc66096
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon May 31 15:49:04 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 31 19:53:14 2021 +0200
fix leak in redaction dialog
Change-Id: I1e918259757021a7c702196be73468d91b244e61
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116451
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx
index 657881979df2..fe43eef840f0 100644
--- a/sfx2/inc/autoredactdialog.hxx
+++ b/sfx2/inc/autoredactdialog.hxx
@@ -92,7 +92,7 @@ enum class StartFileDialogType
class SfxAutoRedactDialog final : public SfxDialogController
{
SfxObjectShellLock m_xDocShell;
- std::vector<std::pair<RedactionTarget*, OUString>> m_aTableTargets;
+ std::vector<std::pair<std::unique_ptr<RedactionTarget>, OUString>> m_aTableTargets;
std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
bool m_bIsValidState;
bool m_bTargetsCopied;
@@ -116,7 +116,7 @@ class SfxAutoRedactDialog final : public SfxDialogController
void StartFileDialog(StartFileDialogType nType, const OUString& rTitle);
/// Carry out proper addition both to the targets box, and to the tabletargets vector.
- void addTarget(RedactionTarget* pTarget);
+ void addTarget(std::unique_ptr<RedactionTarget> pTarget);
/// Clear all targets both visually and from the targets vector
void clearTargets();
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 32c9eb7c9502..eaa90476ea1f 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -366,7 +366,8 @@ boost::property_tree::ptree redactionTargetToJSON(const RedactionTarget* pTarget
return aNode;
}
-RedactionTarget* JSONtoRedactionTarget(const boost::property_tree::ptree::value_type& rValue)
+std::unique_ptr<RedactionTarget>
+JSONtoRedactionTarget(const boost::property_tree::ptree::value_type& rValue)
{
OUString sName = OUString::fromUtf8(rValue.second.get<std::string>("sName").c_str());
RedactionTargetType eType
@@ -378,10 +379,8 @@ RedactionTarget* JSONtoRedactionTarget(const boost::property_tree::ptree::value_
= OUString::fromUtf8(rValue.second.get<std::string>("bWholeWords").c_str()).toBoolean();
sal_uInt32 nID = atoi(rValue.second.get<std::string>("nID").c_str());
- RedactionTarget* pTarget
- = new RedactionTarget({ sName, eType, sContent, bCaseSensitive, bWholeWords, nID });
-
- return pTarget;
+ return std::unique_ptr<RedactionTarget>(
+ new RedactionTarget{ sName, eType, sContent, bCaseSensitive, bWholeWords, nID });
}
}
@@ -418,8 +417,7 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void)
for (const boost::property_tree::ptree::value_type& rValue :
aTargetsJSON.get_child("RedactionTargets"))
{
- RedactionTarget* pTarget = JSONtoRedactionTarget(rValue);
- addTarget(pTarget);
+ addTarget(JSONtoRedactionTarget(rValue));
}
}
catch (css::uno::Exception& e)
@@ -454,7 +452,8 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, sfx2::FileDialogHelper*, void)
boost::property_tree::ptree aTargetsArray;
for (const auto& targetPair : m_aTableTargets)
{
- aTargetsArray.push_back(std::make_pair("", redactionTargetToJSON(targetPair.first)));
+ aTargetsArray.push_back(
+ std::make_pair("", redactionTargetToJSON(targetPair.first.get())));
}
// Build the JSON tree
@@ -496,21 +495,21 @@ void SfxAutoRedactDialog::StartFileDialog(StartFileDialogType nType, const OUStr
m_pFileDlg->StartExecuteModal(aDlgClosedLink);
}
-void SfxAutoRedactDialog::addTarget(RedactionTarget* pTarget)
+void SfxAutoRedactDialog::addTarget(std::unique_ptr<RedactionTarget> pTarget)
{
// Only the visual/display part
- m_xTargetsBox->InsertTarget(pTarget);
+ m_xTargetsBox->InsertTarget(pTarget.get());
// Actually add to the targets vector
- if (m_xTargetsBox->GetTargetByName(pTarget->sName))
- m_aTableTargets.emplace_back(pTarget, pTarget->sName);
+ auto name = pTarget->sName;
+ if (m_xTargetsBox->GetTargetByName(name))
+ m_aTableTargets.emplace_back(std::move(pTarget), name);
else
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
getDialog(), VclMessageType::Warning, VclButtonsType::Ok,
SfxResId(STR_REDACTION_TARGET_ADD_ERROR)));
xBox->run();
- delete pTarget;
}
}
@@ -520,11 +519,6 @@ void SfxAutoRedactDialog::clearTargets()
m_xTargetsBox->clear();
// Clear the targets vector
- auto delTarget
- = [](const std::pair<RedactionTarget*, OUString>& targetPair) { delete targetPair.first; };
-
- std::for_each(m_aTableTargets.begin(), m_aTableTargets.end(), delTarget);
-
m_aTableTargets.clear();
}
@@ -568,8 +562,7 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
for (const boost::property_tree::ptree::value_type& rValue :
aTargetsJSON.get_child("RedactionTargets"))
{
- RedactionTarget* pTarget = JSONtoRedactionTarget(rValue);
- addTarget(pTarget);
+ addTarget(JSONtoRedactionTarget(rValue));
}
}
catch (css::uno::Exception& e)
@@ -606,7 +599,8 @@ SfxAutoRedactDialog::~SfxAutoRedactDialog()
boost::property_tree::ptree aTargetsArray;
for (const auto& targetPair : m_aTableTargets)
{
- aTargetsArray.push_back(std::make_pair("", redactionTargetToJSON(targetPair.first)));
+ aTargetsArray.push_back(
+ std::make_pair("", redactionTargetToJSON(targetPair.first.get())));
}
// Build the JSON tree
commit ec49596a3e66163ce811e8b64808df249a5cf637
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon May 31 10:19:39 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 31 19:53:02 2021 +0200
flatten SfxDocTplService_Impl a little
Change-Id: Id3344141e4b65855717d4d480ab1a3a498fa2a1c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116476
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index 4d9d521eeaa1..4e01f35583c7 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -184,7 +184,7 @@ class SfxDocTplService_Impl
Sequence< OUString > maTemplateDirs;
Sequence< OUString > maInternalTemplateDirs;
OUString maRootURL;
- std::vector< std::unique_ptr<NamePair_Impl> > maNames;
+ std::vector< NamePair_Impl > maNames;
lang::Locale maLocale;
Content maRootContent;
bool mbIsInitialized : 1;
@@ -501,11 +501,11 @@ void SfxDocTplService_Impl::readFolderList()
const size_t nCount = std::min(SAL_N_ELEMENTS(TEMPLATE_SHORT_NAMES_ARY), SAL_N_ELEMENTS(TEMPLATE_LONG_NAMES_ARY));
for (size_t i = 0; i < nCount; ++i)
{
- std::unique_ptr<NamePair_Impl> pPair( new NamePair_Impl );
- pPair->maShortName = OUString::createFromAscii(TEMPLATE_SHORT_NAMES_ARY[i]);
- pPair->maLongName = SfxResId(TEMPLATE_LONG_NAMES_ARY[i]);
+ NamePair_Impl aPair;
+ aPair.maShortName = OUString::createFromAscii(TEMPLATE_SHORT_NAMES_ARY[i]);
+ aPair.maLongName = SfxResId(TEMPLATE_LONG_NAMES_ARY[i]);
- maNames.push_back( std::move(pPair) );
+ maNames.push_back( aPair );
}
}
@@ -514,11 +514,11 @@ OUString SfxDocTplService_Impl::getLongName( const OUString& rShortName )
{
OUString aRet;
- for (auto const & pPair : maNames)
+ for (auto const & rPair : maNames)
{
- if ( pPair->maShortName == rShortName )
+ if ( rPair.maShortName == rShortName )
{
- aRet = pPair->maLongName;
+ aRet = rPair.maLongName;
break;
}
}
More information about the Libreoffice-commits
mailing list