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 /basic/source/runtime | |
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 'basic/source/runtime')
-rw-r--r-- | basic/source/runtime/methods.cxx | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 07e37f2bb6b5..aad84105a293 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -3718,10 +3718,10 @@ RTLFUNC(Shell) ++iter; sal_uInt16 nParamCount = sal::static_int_cast< sal_uInt16 >(aTokenList.size() - 1 ); - rtl_uString** pParamList = nullptr; + std::unique_ptr<rtl_uString*[]> pParamList; if( nParamCount ) { - pParamList = new rtl_uString*[nParamCount]; + pParamList.reset( new rtl_uString*[nParamCount]); for(int iList = 0; iter != aTokenList.end(); ++iList, ++iter) { const OUString& rParamStr = (*iter); @@ -3734,7 +3734,7 @@ RTLFUNC(Shell) oslProcess pApp; bool bSucc = osl_executeProcess( aOUStrProgURL.pData, - pParamList, + pParamList.get(), nParamCount, nOptions, nullptr, @@ -3753,8 +3753,6 @@ RTLFUNC(Shell) rtl_uString_release(pParamList[j]); } - delete [] pParamList; - if( !bSucc ) { StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND ); @@ -4352,7 +4350,7 @@ RTLFUNC(StrConv) // convert the string to byte string, preserving unicode (2 bytes per character) sal_Int32 nSize = aNewStr.getLength()*2; const sal_Unicode* pSrc = aNewStr.getStr(); - sal_Char* pChar = new sal_Char[nSize+1]; + std::unique_ptr<sal_Char[]> pChar(new sal_Char[nSize+1]); for( sal_Int32 i=0; i < nSize; i++ ) { pChar[i] = static_cast< sal_Char >( (i%2) ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff ); @@ -4362,8 +4360,7 @@ RTLFUNC(StrConv) } } pChar[nSize] = '\0'; - OString aOStr(pChar); - delete[] pChar; + OString aOStr(pChar.get()); // there is no concept about default codepage in unix. so it is incorrectly in unix OUString aOUStr = OStringToOUString(aOStr, osl_getThreadTextEncoding()); |