diff options
author | Noel Grandin <noel@peralex.com> | 2015-11-10 13:36:34 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-11-11 07:16:20 +0000 |
commit | db17d3c17c40d6b0e92392cf3c6e343d1d17b771 (patch) | |
tree | 9d562fcf764e7717df9585ef0e735a12ea4aaa16 /sdext/source/minimizer/pppoptimizertoken.cxx | |
parent | 2ce9e4be4a438203382cb9cca824ce3e90647f3a (diff) |
new loplugin: memoryvar
detect when we can convert a new/delete sequence on a local variable to
use std::unique_ptr
Change-Id: Iecae4e4197eccdfacfce2eed39aa4a69e4a660bc
Reviewed-on: https://gerrit.libreoffice.org/19884
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sdext/source/minimizer/pppoptimizertoken.cxx')
-rw-r--r-- | sdext/source/minimizer/pppoptimizertoken.cxx | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sdext/source/minimizer/pppoptimizertoken.cxx b/sdext/source/minimizer/pppoptimizertoken.cxx index d24b35e2998d..d99c49bfb15b 100644 --- a/sdext/source/minimizer/pppoptimizertoken.cxx +++ b/sdext/source/minimizer/pppoptimizertoken.cxx @@ -23,6 +23,7 @@ #include <sal/macros.h> #include <string.h> #include <unordered_map> +#include <memory> typedef std::unordered_map< const char*, PPPOptimizerTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap; static TypeNameHashMap* pHashMap = nullptr; @@ -172,12 +173,11 @@ PPPOptimizerTokenEnum TKGet( const OUString& rToken ) } PPPOptimizerTokenEnum eRetValue = TK_NotFound; int i, nLen = rToken.getLength(); - char* pBuf = new char[ nLen + 1 ]; + std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]); for ( i = 0; i < nLen; i++ ) pBuf[ i ] = (char)rToken[ i ]; pBuf[ i ] = 0; - TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) ); - delete[] pBuf; + TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf.get() ) ); if ( aHashIter != pHashMap->end() ) eRetValue = (*aHashIter).second; return eRetValue; |