From 200ca388246e525f6e8f909766977f534c0c897e Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 21 Jun 2018 15:32:52 +0200 Subject: teach useuniqueptr loplugin about calling delete on a param which is often a useful indicator that the callers can be made to use std::unique_ptr Change-Id: Idb1745d1f58dbcf389c9f60f1a5728d7d092ade5 Reviewed-on: https://gerrit.libreoffice.org/56238 Tested-by: Jenkins Reviewed-by: Noel Grandin --- tools/source/generic/config.cxx | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'tools') diff --git a/tools/source/generic/config.cxx b/tools/source/generic/config.cxx index 55ce2bdc03b8..169f6e6455aa 100644 --- a/tools/source/generic/config.cxx +++ b/tools/source/generic/config.cxx @@ -578,35 +578,27 @@ static void ImplDeleteConfigData( ImplConfigData* pData ) pData->mpFirstGroup = nullptr; } -static ImplConfigData* ImplGetConfigData( const OUString& rFileName ) +static std::unique_ptr ImplGetConfigData( const OUString& rFileName ) { - ImplConfigData* pData; - - pData = new ImplConfigData; + std::unique_ptr pData(new ImplConfigData); pData->maFileName = rFileName; pData->mpFirstGroup = nullptr; pData->mnDataUpdateId = 0; pData->meLineEnd = LINEEND_CRLF; pData->mbRead = false; pData->mbIsUTF8BOM = false; - ImplReadConfig( pData ); + ImplReadConfig( pData.get() ); return pData; } -static void ImplFreeConfigData( ImplConfigData* pDelData ) -{ - ImplDeleteConfigData( pDelData ); - delete pDelData; -} - bool Config::ImplUpdateConfig() const { // Re-read file if timestamp differs if ( mpData->mnTimeStamp != ImplSysGetConfigTimeStamp( maFileName ) ) { - ImplDeleteConfigData( mpData ); - ImplReadConfig( mpData ); + ImplDeleteConfigData( mpData.get() ); + ImplReadConfig( mpData.get() ); mpData->mnDataUpdateId++; return true; } @@ -667,7 +659,7 @@ Config::~Config() SAL_INFO("tools.generic", "Config::~Config()" ); Flush(); - ImplFreeConfigData( mpData ); + ImplDeleteConfigData( mpData.get() ); } void Config::SetGroup(const OString& rGroup) @@ -973,7 +965,7 @@ OString Config::ReadKey(sal_uInt16 nKey) const void Config::Flush() { if ( mpData->mbModified ) - ImplWriteConfig( mpData ); + ImplWriteConfig( mpData.get() ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit