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 | |
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>
46 files changed, 503 insertions, 360 deletions
diff --git a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx index 0ccebe9fb38d..71804b3fe970 100644 --- a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx +++ b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx @@ -29,6 +29,7 @@ #include <vector> #include <algorithm> +#include <memory> #define SUBDIVIDE_FOR_CUT_TEST_COUNT (50) @@ -887,7 +888,7 @@ namespace basegfx else { // first solve self cuts and self touches for all contained single polygons - temporaryPolygonData *pTempData = new temporaryPolygonData[nCount]; + std::unique_ptr<temporaryPolygonData[]> pTempData(new temporaryPolygonData[nCount]); sal_uInt32 a, b; for(a = 0L; a < nCount; a++) @@ -934,8 +935,6 @@ namespace basegfx { aRetval.append(mergeTemporaryPointsAndPolygon(pTempData[a].getPolygon(), pTempData[a].getTemporaryPointVector())); } - - delete[] pTempData; } return aRetval; 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()); diff --git a/basic/source/sbx/sbxstr.cxx b/basic/source/sbx/sbxstr.cxx index f66680b82f4c..71dffbf73df7 100644 --- a/basic/source/sbx/sbxstr.cxx +++ b/basic/source/sbx/sbxstr.cxx @@ -25,6 +25,7 @@ #include "sbxres.hxx" #include "runtime.hxx" #include <rtl/ustrbuf.hxx> +#include <memory> // The conversion of an item onto String was handled via the Put-Methods // of the several data types to avoid duplicated code. @@ -161,10 +162,13 @@ void ImpPutString( SbxValues* p, const OUString* n ) { SbxValues aTmp; aTmp.eType = SbxSTRING; - OUString* pTmp = nullptr; + std::unique_ptr<OUString> pTmp; // as a precaution, if a NULL-Ptr appears if( !n ) - n = pTmp = new OUString; + { + pTmp.reset(new OUString); + n = pTmp.get(); + } aTmp.pOUString = const_cast<OUString*>(n); switch( +p->eType ) { @@ -252,7 +256,6 @@ void ImpPutString( SbxValues* p, const OUString* n ) default: SbxBase::SetError( ERRCODE_SBX_CONVERSION ); } - delete pTmp; } diff --git a/compilerplugins/clang/memoryvar.cxx b/compilerplugins/clang/memoryvar.cxx new file mode 100644 index 000000000000..2e776901c415 --- /dev/null +++ b/compilerplugins/clang/memoryvar.cxx @@ -0,0 +1,239 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <string> +#include <iostream> +#include <map> +#include <set> + +#include "plugin.hxx" +#include "compat.hxx" +#include "clang/AST/CXXInheritance.h" + +// Check for local variables that we are calling delete on + +namespace +{ + +class MemoryVar: + public RecursiveASTVisitor<MemoryVar>, public loplugin::Plugin +{ +public: + explicit MemoryVar(InstantiationData const & data): Plugin(data) {} + + virtual void run() override { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + + bool TraverseFunctionDecl(FunctionDecl*); + bool VisitCXXDeleteExpr(const CXXDeleteExpr*); + bool VisitCXXNewExpr(const CXXNewExpr* ); + bool VisitBinaryOperator(const BinaryOperator*); + bool VisitReturnStmt(const ReturnStmt*); + +private: + bool mbChecking; + std::set<SourceLocation> maVarUsesSet; + std::set<SourceLocation> maVarNewSet; + std::set<SourceLocation> maVarIgnoreSet; + std::map<SourceLocation,SourceRange> maVarDeclSourceRangeMap; + std::map<SourceLocation,SourceRange> maVarDeleteSourceRangeMap; + StringRef getFilename(SourceLocation loc); +}; + +StringRef MemoryVar::getFilename(SourceLocation loc) +{ + SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc); + StringRef name { compiler.getSourceManager().getFilename(spellingLocation) }; + return name; +} + +bool MemoryVar::TraverseFunctionDecl(FunctionDecl * decl) +{ + if (ignoreLocation(decl)) { + return true; + } + if (!decl->hasBody() || !decl->isThisDeclarationADefinition()) { + return true; + } + + maVarUsesSet.clear(); + maVarNewSet.clear(); + maVarIgnoreSet.clear(); + maVarDeclSourceRangeMap.clear(); + maVarDeleteSourceRangeMap.clear(); + + assert(!mbChecking); + mbChecking = true; + TraverseStmt(decl->getBody()); + mbChecking = false; + + for (const auto& varLoc : maVarUsesSet) + { + // checking the location of the var instead of the function because for some reason + // I'm not getting accurate results from clang right now + StringRef aFileName = getFilename(varLoc); + // TODO these files are doing some weird stuff I don't know how to ignore yet + if (aFileName.startswith(SRCDIR "/vcl/source/filter")) { + return true; + } + if (aFileName.startswith(SRCDIR "/sw/source/core/layout/frmtool.cxx")) { + return true; + } + + + if (maVarNewSet.find(varLoc) == maVarNewSet.end()) + continue; + if (maVarIgnoreSet.find(varLoc) != maVarIgnoreSet.end()) + continue; + + report(DiagnosticsEngine::Warning, + "calling new and delete on a local var, rather use std::unique_ptr", + varLoc) + << maVarDeclSourceRangeMap[varLoc]; + report(DiagnosticsEngine::Note, + "delete called here", + maVarDeleteSourceRangeMap[varLoc].getBegin()) + << maVarDeleteSourceRangeMap[varLoc]; + cout << "xxxx " << aFileName.str() << endl; + } + return true; +} + +bool MemoryVar::VisitCXXDeleteExpr(const CXXDeleteExpr *deleteExpr) +{ + if (!mbChecking) + return true; + if (ignoreLocation(deleteExpr)) { + return true; + } + const Expr* argumentExpr = deleteExpr->getArgument(); + if (isa<CastExpr>(argumentExpr)) { + argumentExpr = dyn_cast<CastExpr>(argumentExpr)->getSubExpr(); + } + const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(argumentExpr); + if (!declRefExpr) + return true; + const Decl* decl = declRefExpr->getDecl(); + if (!isa<VarDecl>(decl) || isa<ParmVarDecl>(decl)) { + return true; + } + const VarDecl * varDecl = dyn_cast<VarDecl>(decl)->getCanonicalDecl(); + if (varDecl->hasGlobalStorage()) { + return true; + } + + SourceLocation loc = varDecl->getLocation(); + + if (maVarUsesSet.find(loc) == maVarUsesSet.end()) { + maVarUsesSet.insert(loc); + maVarDeclSourceRangeMap[loc] = varDecl->getSourceRange(); + maVarDeleteSourceRangeMap[loc] = declRefExpr->getSourceRange(); + } + return true; +} + +bool MemoryVar::VisitCXXNewExpr(const CXXNewExpr *newExpr) +{ + if (!mbChecking) + return true; + if (ignoreLocation(newExpr)) { + return true; + } + const Stmt* stmt = parentStmt(newExpr); + + const DeclStmt* declStmt = dyn_cast<DeclStmt>(stmt); + if (declStmt) { + const VarDecl* varDecl = dyn_cast<VarDecl>(declStmt->getSingleDecl()); + if (varDecl) { + varDecl = varDecl->getCanonicalDecl(); + SourceLocation loc = varDecl->getLocation(); + maVarNewSet.insert(loc); + } + return true; + } + + const BinaryOperator* binaryOp = dyn_cast<BinaryOperator>(stmt); + if (binaryOp && binaryOp->getOpcode() == BO_Assign) { + const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(binaryOp->getLHS()); + if (declRefExpr) { + const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + if (varDecl) { + varDecl = varDecl->getCanonicalDecl(); + SourceLocation loc = varDecl->getLocation(); + maVarNewSet.insert(loc); + } + } + } + return true; +} + +// Ignore cases where the variable in question is assigned to another variable +bool MemoryVar::VisitBinaryOperator(const BinaryOperator *binaryOp) +{ + if (!mbChecking) + return true; + if (ignoreLocation(binaryOp)) { + return true; + } + if (binaryOp->getOpcode() != BO_Assign) { + return true; + } + const Expr* expr = binaryOp->getRHS(); + // unwrap casts + while (isa<CastExpr>(expr)) { + expr = dyn_cast<CastExpr>(expr)->getSubExpr(); + } + const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(expr); + if (!declRefExpr) { + return true; + } + const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + if (!varDecl) { + return true; + } + varDecl = varDecl->getCanonicalDecl(); + maVarIgnoreSet.insert(varDecl->getLocation()); + return true; +} + +// Ignore cases where the variable in question is returned from a function +bool MemoryVar::VisitReturnStmt(const ReturnStmt *returnStmt) +{ + if (!mbChecking) + return true; + if (ignoreLocation(returnStmt)) { + return true; + } + const Expr* expr = returnStmt->getRetValue(); + if (!expr) { + return true; + } + // unwrap casts + while (isa<CastExpr>(expr)) { + expr = dyn_cast<CastExpr>(expr)->getSubExpr(); + } + const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(expr); + if (!declRefExpr) { + return true; + } + const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + if (!varDecl) { + return true; + } + varDecl = varDecl->getCanonicalDecl(); + maVarIgnoreSet.insert(varDecl->getLocation()); + return true; +} + +loplugin::Plugin::Registration< MemoryVar > X("memoryvar"); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index 476b7c41f966..2b83ef806152 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -895,11 +895,10 @@ SvStream& connectivity::dbase::WriteONDXPage(SvStream &rStream, const ONDXPage& sal_Size nRemainSize = nBufferSize - nTell; if ( nRemainSize <= nBufferSize ) { - char* pEmptyData = new char[nRemainSize]; - memset(pEmptyData,0x00,nRemainSize); - rStream.Write(pEmptyData, nRemainSize); + std::unique_ptr<char[]> pEmptyData( new char[nRemainSize] ); + memset(pEmptyData.get(), 0x00, nRemainSize); + rStream.Write(pEmptyData.get(), nRemainSize); rStream.Seek(nTell); - delete [] pEmptyData; } } return rStream; diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index a725df434609..c57fd075df9a 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -107,6 +107,7 @@ #include <connectivity/FValue.hxx> #include <editeng/justifyitem.hxx> +#include <memory> namespace dbaui { @@ -825,7 +826,7 @@ bool callColumnFormatDialog(vcl::Window* _pParent, pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why pPool->FreezeIdRanges(); // the same - SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap); + std::unique_ptr<SfxItemSet> pFormatDescriptor(new SfxItemSet(*pPool, aAttrMap)); // fill it pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY)); bool bText = false; @@ -852,7 +853,7 @@ bool callColumnFormatDialog(vcl::Window* _pParent, } { // want the dialog to be destroyed before our set - ScopedVclPtrInstance< SbaSbAttrDlg > aDlg(_pParent, pFormatDescriptor, _pFormatter, _bHasFormat); + ScopedVclPtrInstance< SbaSbAttrDlg > aDlg(_pParent, pFormatDescriptor.get(), _pFormatter, _bHasFormat); if (RET_OK == aDlg->Execute()) { // ItemSet->UNO @@ -890,7 +891,6 @@ bool callColumnFormatDialog(vcl::Window* _pParent, } } - delete pFormatDescriptor; SfxItemPool::Free(pPool); for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i) delete pDefaults[i]; diff --git a/extensions/source/plugin/unx/npnapi.cxx b/extensions/source/plugin/unx/npnapi.cxx index 3a7eca7b04a5..7f70a5e39ea7 100644 --- a/extensions/source/plugin/unx/npnapi.cxx +++ b/extensions/source/plugin/unx/npnapi.cxx @@ -44,6 +44,7 @@ #include <config_vclplug.h> #include <npwrap.hxx> +#include <memory> extern PluginConnector* pConnector; extern XtAppContext app_context; @@ -270,7 +271,7 @@ static NPError l_NPN_RequestRead( NPStream* stream, NPByteRange* rangeList ) pRange = pRange->next; } - sal_uInt32* pArray = new sal_uInt32[ 2 * nRanges ]; + std::unique_ptr<sal_uInt32[]> pArray(new sal_uInt32[ 2 * nRanges ]); pRange = rangeList; sal_uInt32 n = 0; while( pRange ) @@ -285,17 +286,15 @@ static NPError l_NPN_RequestRead( NPStream* stream, NPByteRange* rangeList ) Transact( eNPN_RequestRead, &nFileID, sizeof( nFileID ), &nRanges, sizeof( nRanges ), - pArray, sizeof( sal_uInt32 ) * 2 * nRanges, + pArray.get(), sizeof( sal_uInt32 ) * 2 * nRanges, NULL ); if( ! pMes ) { - delete[] pArray; return NPERR_GENERIC_ERROR; } NPError aRet = PluginConnector::GetNPError( pMes ); - delete [] pArray; delete pMes; return aRet; } diff --git a/filter/source/graphicfilter/ieps/ieps.cxx b/filter/source/graphicfilter/ieps/ieps.cxx index 714720bf6385..02d42597a134 100644 --- a/filter/source/graphicfilter/ieps/ieps.cxx +++ b/filter/source/graphicfilter/ieps/ieps.cxx @@ -581,19 +581,17 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) nPSStreamPos = nOrigPos; // no preview available _>so we must get the size manually nPSSize = rStream.Seek( STREAM_SEEK_TO_END ) - nOrigPos; } - sal_uInt8* pHeader = new sal_uInt8[ 22 ]; + std::unique_ptr<sal_uInt8[]> pHeader( new sal_uInt8[ 22 ] ); rStream.Seek( nPSStreamPos ); - rStream.Read( pHeader, 22 ); // check PostScript header - if ( ImplSearchEntry( pHeader, reinterpret_cast<sal_uInt8 const *>("%!PS-Adobe"), 10, 10 ) && + rStream.Read( pHeader.get(), 22 ); // check PostScript header + if ( ImplSearchEntry( pHeader.get(), reinterpret_cast<sal_uInt8 const *>("%!PS-Adobe"), 10, 10 ) && ImplSearchEntry( &pHeader[ 15 ], reinterpret_cast<sal_uInt8 const *>("EPS"), 3, 3 ) ) { - bool bGraphicLinkCreated = false; - rStream.Seek( nPSStreamPos ); - sal_uInt8* pBuf = new sal_uInt8[ nPSSize ]; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nPSSize ] ); sal_uInt32 nBufStartPos = rStream.Tell(); - sal_uInt32 nBytesRead = rStream.Read( pBuf, nPSSize ); + sal_uInt32 nBytesRead = rStream.Read( pBuf.get(), nPSSize ); if ( nBytesRead == nPSSize ) { sal_uInt32 nSecurityCount = 32; @@ -601,7 +599,7 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) // the eps prolog if (!bHasPreview && nBytesRead >= nSecurityCount) { - sal_uInt8* pDest = ImplSearchEntry( pBuf, reinterpret_cast<sal_uInt8 const *>("%%BeginPreview:"), nBytesRead - nSecurityCount, 15 ); + sal_uInt8* pDest = ImplSearchEntry( pBuf.get(), reinterpret_cast<sal_uInt8 const *>("%%BeginPreview:"), nBytesRead - nSecurityCount, 15 ); if ( pDest ) { pDest += 15; @@ -612,7 +610,7 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) pDest = ImplSearchEntry( pDest, reinterpret_cast<sal_uInt8 const *>("%"), 16, 1 ); // go to the first Scanline if ( nSecurityCount && pDest && nWidth && nHeight && ( ( nBitDepth == 1 ) || ( nBitDepth == 8 ) ) && nScanLines ) { - rStream.Seek( nBufStartPos + ( pDest - pBuf ) ); + rStream.Seek( nBufStartPos + ( pDest - pBuf.get() ) ); Bitmap aBitmap( Size( nWidth, nHeight ), 1 ); BitmapWriteAccess* pAcc = aBitmap.AcquireWriteAccess(); @@ -700,7 +698,7 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) } } - sal_uInt8* pDest = ImplSearchEntry( pBuf, reinterpret_cast<sal_uInt8 const *>("%%BoundingBox:"), nBytesRead, 14 ); + sal_uInt8* pDest = ImplSearchEntry( pBuf.get(), reinterpret_cast<sal_uInt8 const *>("%%BoundingBox:"), nBytesRead, 14 ); if ( pDest ) { nSecurityCount = 100; @@ -713,8 +711,6 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) } if ( nSecurityCount) { - bGraphicLinkCreated = true; - GfxLink aGfxLink( pBuf, nPSSize, GFX_LINK_TYPE_EPS_BUFFER, true ) ; GDIMetaFile aMtf; long nWidth = nNumb[2] - nNumb[0] + 1; @@ -723,18 +719,20 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) // if there is no preview -> try with gs to make one if (!bHasPreview && !utl::ConfigManager::IsAvoidConfig()) { - bHasPreview = RenderAsEMF(pBuf, nBytesRead, aGraphic); + bHasPreview = RenderAsEMF(pBuf.get(), nBytesRead, aGraphic); if (!bHasPreview) - bHasPreview = RenderAsBMP(pBuf, nBytesRead, aGraphic); + bHasPreview = RenderAsBMP(pBuf.get(), nBytesRead, aGraphic); } // if there is no preview -> make a red box if( !bHasPreview ) { - MakePreview(pBuf, nBytesRead, nWidth, nHeight, + MakePreview(pBuf.get(), nBytesRead, nWidth, nHeight, aGraphic); } + GfxLink aGfxLink( pBuf.get(), nPSSize, GFX_LINK_TYPE_EPS_BUFFER, true ) ; + pBuf.release(); aMtf.AddAction( static_cast<MetaAction*>( new MetaEPSAction( Point(), Size( nWidth, nHeight ), aGfxLink, aGraphic.GetGDIMetaFile() ) ) ); CreateMtfReplacementAction( aMtf, rStream, nOrigPos, nPSSize, nPosWMF, nSizeWMF, nPosTIFF, nSizeTIFF ); @@ -746,11 +744,7 @@ ipsGraphicImport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* ) } } } - - if ( !bGraphicLinkCreated ) - delete[] pBuf; } - delete[] pHeader; rStream.SetEndian(nOldFormat); rStream.Seek( nOrigPos ); return bRetValue; diff --git a/hwpfilter/source/cspline.cxx b/hwpfilter/source/cspline.cxx index 90f8c1c3520d..87d36eeacc0f 100644 --- a/hwpfilter/source/cspline.cxx +++ b/hwpfilter/source/cspline.cxx @@ -48,6 +48,7 @@ // usage. #include <sal/config.h> +#include <memory> #include "cspline.h" #include "solver.h" @@ -58,9 +59,9 @@ void NaturalSpline (int N, double* x, double* a, double*& b, double*& c, const double oneThird = 1.0/3.0; int i; - double* h = new double[N]; - double* hdiff = new double[N]; - double* alpha = new double[N]; + std::unique_ptr<double[]> h(new double[N]); + std::unique_ptr<double[]> hdiff(new double[N]); + std::unique_ptr<double[]> alpha(new double[N]); for (i = 0; i < N; i++){ h[i] = x[i+1]-x[i]; @@ -76,9 +77,9 @@ void NaturalSpline (int N, double* x, double* a, double*& b, double*& c, alpha[i] = numer/denom; } - double* ell = new double[N+1]; - double* mu = new double[N]; - double* z = new double[N+1]; + std::unique_ptr<double[]> ell(new double[N+1]); + std::unique_ptr<double[]> mu(new double[N]); + std::unique_ptr<double[]> z(new double[N+1]); double recip; ell[0] = 1.0; @@ -108,19 +109,12 @@ void NaturalSpline (int N, double* x, double* a, double*& b, double*& c, b[i] = recip*(a[i+1]-a[i])-h[i]*(c[i+1]+2.0*c[i])*oneThird; d[i] = oneThird*recip*(c[i+1]-c[i]); } - - delete[] h; - delete[] hdiff; - delete[] alpha; - delete[] ell; - delete[] mu; - delete[] z; } void PeriodicSpline (int N, double* x, double* a, double*& b, double*& c, double*& d) { - double* h = new double[N]; + std::unique_ptr<double[]> h(new double[N]); int i; for (i = 0; i < N; i++) h[i] = x[i+1]-x[i]; @@ -163,7 +157,6 @@ void PeriodicSpline (int N, double* x, double* a, double*& b, double*& c, d[i] = oneThird*(c[i+1]-c[i])/h[i]; } - delete[] h; mgcLinearSystemD::DeleteMatrix(N+1,mat); } diff --git a/idl/source/prj/svidl.cxx b/idl/source/prj/svidl.cxx index a6cb296ed8f2..4b8d4b9820f4 100644 --- a/idl/source/prj/svidl.cxx +++ b/idl/source/prj/svidl.cxx @@ -25,6 +25,7 @@ #include <command.hxx> #include <rtl/ustring.hxx> #include <osl/file.hxx> +#include <memory> #define BR 0x8000 bool FileMove_Impl( const OUString & rFile1, const OUString & rFile2, bool bImmerVerschieben ) @@ -38,13 +39,13 @@ bool FileMove_Impl( const OUString & rFile1, const OUString & rFile2, bool bImme SvFileStream aOutStm2( rFile2, STREAM_STD_READ ); if( aOutStm1.GetError() == SVSTREAM_OK ) { - sal_uInt8 * pBuf1 = new sal_uInt8[ BR ]; - sal_uInt8 * pBuf2 = new sal_uInt8[ BR ]; - nC1 = aOutStm1.Read( pBuf1, BR ); - nC2 = aOutStm2.Read( pBuf2, BR ); + std::unique_ptr<sal_uInt8[]> pBuf1(new sal_uInt8[ BR ]); + std::unique_ptr<sal_uInt8[]> pBuf2(new sal_uInt8[ BR ]); + nC1 = aOutStm1.Read( pBuf1.get(), BR ); + nC2 = aOutStm2.Read( pBuf2.get(), BR ); while( nC1 == nC2 ) { - if( memcmp( pBuf1, pBuf2, nC1 ) ) + if( memcmp( pBuf1.get(), pBuf2.get(), nC1 ) ) { nC1++; break; @@ -53,12 +54,10 @@ bool FileMove_Impl( const OUString & rFile1, const OUString & rFile2, bool bImme { if( 0x8000 != nC1 ) break; - nC1 = aOutStm1.Read( pBuf1, BR ); - nC2 = aOutStm2.Read( pBuf2, BR ); + nC1 = aOutStm1.Read( pBuf1.get(), BR ); + nC2 = aOutStm2.Read( pBuf2.get(), BR ); } } - delete[] pBuf1; - delete[] pBuf2; } } OUString fileURL2; @@ -114,7 +113,7 @@ int main ( int argc, char ** argv) printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" ); Init(); - SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand); + std::unique_ptr<SvIdlWorkingBase> pDataBase( new SvIdlWorkingBase(aCommand)); int nExit = 0; if( !aCommand.aExportFile.isEmpty() ) @@ -126,7 +125,7 @@ int main ( int argc, char ** argv) pDataBase->SetExportFile( fileStatus.getFileName() ); } - if( ReadIdl( pDataBase, aCommand ) ) + if( ReadIdl( pDataBase.get(), aCommand ) ) { if( nExit == 0 && !aCommand.aSlotMapFile.isEmpty() ) { @@ -210,7 +209,6 @@ int main ( int argc, char ** argv) } } - delete pDataBase; if( nExit != 0 ) fprintf( stderr, "svidl terminated with errors\n" ); return nExit; diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index aaf2dfd561e0..207f7ada700e 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -31,6 +31,7 @@ #include "helpmerge.hxx" #include "common.hxx" +#include <memory> #ifndef TESTDRIVER @@ -81,10 +82,10 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) std::cerr << "Helpex error: cannot open input file\n"; return 1; } - MergeDataFile* pMergeDataFile = nullptr; + std::unique_ptr<MergeDataFile> pMergeDataFile; if( aArgs.m_sLanguage != "qtz") { - pMergeDataFile = new MergeDataFile(aArgs.m_sMergeSrc, OString(), false, false ); + pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, OString(), false, false )); } std::string sTemp; aInput >> sTemp; @@ -97,28 +98,26 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) aArgs.m_sOutputFile + sXhpFile.copy( sXhpFile.lastIndexOf('/') )); if( !aParser.Merge( aArgs.m_sMergeSrc, sOutput, - aArgs.m_sLanguage, pMergeDataFile )) + aArgs.m_sLanguage, pMergeDataFile.get() )) { hasNoError = false; } aInput >> sTemp; } aInput.close(); - delete pMergeDataFile; } else { HelpParser aParser( aArgs.m_sInputFile ); - MergeDataFile* pMergeDataFile = nullptr; + std::unique_ptr<MergeDataFile> pMergeDataFile; if( aArgs.m_sLanguage != "qtz") { - pMergeDataFile = new MergeDataFile(aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false ); + pMergeDataFile.reset(new MergeDataFile(aArgs.m_sMergeSrc, aArgs.m_sInputFile, false, false )); } hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile, - aArgs.m_sLanguage, pMergeDataFile ); - delete pMergeDataFile; + aArgs.m_sLanguage, pMergeDataFile.get() ); } } else diff --git a/opencl/source/opencl_device.cxx b/opencl/source/opencl_device.cxx index 112e03c6d968..9a10d3651d1d 100644 --- a/opencl/source/opencl_device.cxx +++ b/opencl/source/opencl_device.cxx @@ -236,8 +236,8 @@ ds_status evaluateScoreForDevice(ds_device* device, void* evalData) clStatus = clGetDeviceInfo(device->oclDeviceID, CL_DEVICE_EXTENSIONS, 0, nullptr, &aDevExtInfoSize); DS_CHECK_STATUS(clStatus, "evaluateScoreForDevice::clGetDeviceInfo"); - char* aExtInfo = new char[aDevExtInfoSize]; - clStatus = clGetDeviceInfo(device->oclDeviceID, CL_DEVICE_EXTENSIONS, sizeof(char) * aDevExtInfoSize, aExtInfo, nullptr); + std::unique_ptr<char[]> aExtInfo(new char[aDevExtInfoSize]); + clStatus = clGetDeviceInfo(device->oclDeviceID, CL_DEVICE_EXTENSIONS, sizeof(char) * aDevExtInfoSize, aExtInfo.get(), nullptr); DS_CHECK_STATUS(clStatus, "evaluateScoreForDevice::clGetDeviceInfo"); bool bKhrFp64Flag = false; bool bAmdFp64Flag = false; @@ -247,7 +247,7 @@ ds_status evaluateScoreForDevice(ds_device* device, void* evalData) tmpOStrStr << std::dec << INPUTSIZE; tmpStr.append(tmpOStrStr.str()); - if ((std::string(aExtInfo)).find("cl_khr_fp64") != std::string::npos) + if ((std::string(aExtInfo.get())).find("cl_khr_fp64") != std::string::npos) { bKhrFp64Flag = true; //buildOption = "-D KHR_DP_EXTENSION -Dfp_t=double -Dfp_t4=double4 -Dfp_t16=double16"; @@ -255,7 +255,7 @@ ds_status evaluateScoreForDevice(ds_device* device, void* evalData) buildOption = tmpStr.c_str(); SAL_INFO("opencl.device", "... has cl_khr_fp64"); } - else if ((std::string(aExtInfo)).find("cl_amd_fp64") != std::string::npos) + else if ((std::string(aExtInfo.get())).find("cl_amd_fp64") != std::string::npos) { bAmdFp64Flag = true; //buildOption = "-D AMD_DP_EXTENSION -Dfp_t=double -Dfp_t4=double4 -Dfp_t16=double16"; @@ -263,7 +263,6 @@ ds_status evaluateScoreForDevice(ds_device* device, void* evalData) buildOption = tmpStr.c_str(); SAL_INFO("opencl.device", "... has cl_amd_fp64"); } - delete[] aExtInfo; if (!bKhrFp64Flag && !bAmdFp64Flag) { diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx index 4a05a5feeceb..7bbcb2c3bce3 100644 --- a/opencl/source/openclwrapper.cxx +++ b/opencl/source/openclwrapper.cxx @@ -221,18 +221,17 @@ bool generatBinFromKernelSource( cl_program program, const char * clFileName ) /* copy over the generated binary. */ if ( binarySize != 0 ) { - char *binary = new char[binarySize]; + std::unique_ptr<char[]> binary(new char[binarySize]); clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARIES, sizeof(char *), &binary, nullptr ); CHECK_OPENCL(clStatus,"clGetProgramInfo"); OString fileName = createFileName(pDevID, clFileName); if ( !writeBinaryToFile( fileName, - binary, binarySize ) ) + binary.get(), binarySize ) ) SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': FAIL"); else SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': success"); - delete[] binary; } return true; } diff --git a/rsc/source/prj/gui.cxx b/rsc/source/prj/gui.cxx index 540563895f44..3a0f0609ca19 100644 --- a/rsc/source/prj/gui.cxx +++ b/rsc/source/prj/gui.cxx @@ -20,6 +20,7 @@ #include <stdlib.h> #include <stdio.h> +#include <memory> #include <gui.hxx> #include <rscrsc.hxx> @@ -48,26 +49,21 @@ int rsc2_main( int argc, char **argv ) ERRTYPE aError; InitRscCompiler(); - RscError* pErrHdl = new RscError( lcl_determineVerbosity( argc, argv ) ); - RscCmdLine* pCmdLine = new RscCmdLine( argc, argv, pErrHdl ); - RscTypCont* pTypCont = new RscTypCont( pErrHdl, + std::unique_ptr<RscError> pErrHdl(new RscError( lcl_determineVerbosity( argc, argv ) )); + std::unique_ptr<RscCmdLine> pCmdLine(new RscCmdLine( argc, argv, pErrHdl.get() )); + std::unique_ptr<RscTypCont> pTypCont(new RscTypCont( pErrHdl.get(), pCmdLine->nByteOrder, pCmdLine->aPath, - pCmdLine->nCommands ); + pCmdLine->nCommands )); if( pErrHdl->nErrors ) aError = ERR_ERROR; else{ - RscCompiler* pCompiler = new RscCompiler( pCmdLine, pTypCont ); + std::unique_ptr<RscCompiler> pCompiler(new RscCompiler( pCmdLine.get(), pTypCont.get() )); aError = pCompiler->Start(); - - delete pCompiler; } - delete pTypCont; - delete pCmdLine; - delete pErrHdl; delete pHS; // wird durch InitRscCompiler erzeugt if( aError.IsOk() ) diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 81bc4152b9dc..f5871f7aa339 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5989,7 +5989,7 @@ void testDataBarLengthImpl(ScDocument* pDoc, ScDataBarLengthData* pData, const S double nMaxVal, ScColorScaleEntryType eMaxType, double nZeroPos, databar::ScAxisPosition eAxisPos) { - ScConditionalFormat* pFormat = new ScConditionalFormat(1, pDoc); + std::unique_ptr<ScConditionalFormat> pFormat(new ScConditionalFormat(1, pDoc)); ScRangeList aRangeList(rRange); pFormat->SetRange(aRangeList); @@ -6021,7 +6021,6 @@ void testDataBarLengthImpl(ScDocument* pDoc, ScDataBarLengthData* pData, const S ASSERT_DOUBLES_EQUAL(pData[i].nLength, xInfo->mnLength); ASSERT_DOUBLES_EQUAL(nZeroPos, xInfo->mnZero); } - delete pFormat; } } diff --git a/sc/source/core/tool/callform.cxx b/sc/source/core/tool/callform.cxx index a859c3ccada1..3334715acf97 100644 --- a/sc/source/core/tool/callform.cxx +++ b/sc/source/core/tool/callform.cxx @@ -25,6 +25,7 @@ #include <osl/module.hxx> #include <osl/file.hxx> #include <unotools/transliterationwrapper.hxx> +#include <memory> #include "callform.hxx" #include "global.hxx" @@ -170,75 +171,69 @@ bool InitExternalFunc(const OUString& rModuleName) OUString aNP; aNP = rModuleName; - bool bRet = false; - osl::Module* pLib = new osl::Module( aNP ); - if (pLib->is()) + std::unique_ptr<osl::Module> pLib(new osl::Module( aNP )); + if (!pLib->is()) + return false; + + oslGenericFunction fpGetCount = pLib->getFunctionSymbol(GETFUNCTIONCOUNT); + oslGenericFunction fpGetData = pLib->getFunctionSymbol(GETFUNCTIONDATA); + if ((fpGetCount == nullptr) || (fpGetData == nullptr)) + return false; + + oslGenericFunction fpIsAsync = pLib->getFunctionSymbol(ISASYNC); + oslGenericFunction fpAdvice = pLib->getFunctionSymbol(ADVICE); + oslGenericFunction fpSetLanguage = pLib->getFunctionSymbol(SETLANGUAGE); + if ( fpSetLanguage ) { - oslGenericFunction fpGetCount = pLib->getFunctionSymbol(GETFUNCTIONCOUNT); - oslGenericFunction fpGetData = pLib->getFunctionSymbol(GETFUNCTIONDATA); - if ((fpGetCount != nullptr) && (fpGetData != nullptr)) + LanguageType eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType(); + sal_uInt16 nLanguage = (sal_uInt16) eLanguage; + (*reinterpret_cast<SetLanguagePtr>(fpSetLanguage))( nLanguage ); + } + + // Module in die Collection aufnehmen + ModuleData* pModuleData = new ModuleData(rModuleName, pLib.release()); + aModuleCollection.insert(pModuleData); + + // Schnittstelle initialisieren + AdvData pfCallBack = &ScAddInAsyncCallBack; + LegacyFuncCollection* pLegacyFuncCol = ScGlobal::GetLegacyFuncCollection(); + sal_uInt16 nCount; + (*reinterpret_cast<GetFuncCountPtr>(fpGetCount))(nCount); + for (sal_uInt16 i=0; i < nCount; i++) + { + sal_Char cFuncName[256]; + sal_Char cInternalName[256]; + sal_uInt16 nParamCount; + ParamType eParamType[MAXFUNCPARAM]; + ParamType eAsyncType = ParamType::NONE; + // initialize all, in case the AddIn behaves bad + cFuncName[0] = 0; + cInternalName[0] = 0; + nParamCount = 0; + for ( sal_uInt16 j=0; j<MAXFUNCPARAM; j++ ) { - oslGenericFunction fpIsAsync = pLib->getFunctionSymbol(ISASYNC); - oslGenericFunction fpAdvice = pLib->getFunctionSymbol(ADVICE); - oslGenericFunction fpSetLanguage = pLib->getFunctionSymbol(SETLANGUAGE); - if ( fpSetLanguage ) - { - LanguageType eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType(); - sal_uInt16 nLanguage = (sal_uInt16) eLanguage; - (*reinterpret_cast<SetLanguagePtr>(fpSetLanguage))( nLanguage ); - } - - // Module in die Collection aufnehmen - ModuleData* pModuleData = new ModuleData(rModuleName, pLib); - aModuleCollection.insert(pModuleData); - - // Schnittstelle initialisieren - AdvData pfCallBack = &ScAddInAsyncCallBack; - LegacyFuncCollection* pLegacyFuncCol = ScGlobal::GetLegacyFuncCollection(); - sal_uInt16 nCount; - (*reinterpret_cast<GetFuncCountPtr>(fpGetCount))(nCount); - for (sal_uInt16 i=0; i < nCount; i++) - { - sal_Char cFuncName[256]; - sal_Char cInternalName[256]; - sal_uInt16 nParamCount; - ParamType eParamType[MAXFUNCPARAM]; - ParamType eAsyncType = ParamType::NONE; - // initialize all, in case the AddIn behaves bad - cFuncName[0] = 0; - cInternalName[0] = 0; - nParamCount = 0; - for ( sal_uInt16 j=0; j<MAXFUNCPARAM; j++ ) - { - eParamType[j] = ParamType::NONE; - } - (*reinterpret_cast<GetFuncDataPtr>(fpGetData))(i, cFuncName, nParamCount, - eParamType, cInternalName); - if( fpIsAsync ) - { - (*reinterpret_cast<IsAsync>(fpIsAsync))(i, &eAsyncType); - if ( fpAdvice && eAsyncType != ParamType::NONE ) - (*reinterpret_cast<Advice>(fpAdvice))( i, pfCallBack ); - } - OUString aInternalName( cInternalName, strlen(cInternalName), osl_getThreadTextEncoding() ); - OUString aFuncName( cFuncName, strlen(cFuncName), osl_getThreadTextEncoding() ); - LegacyFuncData* pLegacyFuncData = new LegacyFuncData( pModuleData, - aInternalName, - aFuncName, - i, - nParamCount, - eParamType, - eAsyncType ); - pLegacyFuncCol->insert(pLegacyFuncData); - } - bRet = true; + eParamType[j] = ParamType::NONE; } - else - delete pLib; + (*reinterpret_cast<GetFuncDataPtr>(fpGetData))(i, cFuncName, nParamCount, + eParamType, cInternalName); + if( fpIsAsync ) + { + (*reinterpret_cast<IsAsync>(fpIsAsync))(i, &eAsyncType); + if ( fpAdvice && eAsyncType != ParamType::NONE ) + (*reinterpret_cast<Advice>(fpAdvice))( i, pfCallBack ); + } + OUString aInternalName( cInternalName, strlen(cInternalName), osl_getThreadTextEncoding() ); + OUString aFuncName( cFuncName, strlen(cFuncName), osl_getThreadTextEncoding() ); + LegacyFuncData* pLegacyFuncData = new LegacyFuncData( pModuleData, + aInternalName, + aFuncName, + i, + nParamCount, + eParamType, + eAsyncType ); + pLegacyFuncCol->insert(pLegacyFuncData); } - else - delete pLib; - return bRet; + return true; #endif } diff --git a/sc/source/filter/starcalc/scflt.cxx b/sc/source/filter/starcalc/scflt.cxx index 7d3a56e77e64..edf6bf72ca74 100644 --- a/sc/source/filter/starcalc/scflt.cxx +++ b/sc/source/filter/starcalc/scflt.cxx @@ -369,14 +369,12 @@ static OUString lcl_MakeOldPageStyleFormatName( sal_uInt16 i ) template < typename T > sal_uLong insert_new( ScCollection* pCollection, SvStream& rStream ) { - T* pData = new (::std::nothrow) T( rStream); + std::unique_ptr<T> pData(new (::std::nothrow) T( rStream)); sal_uLong nError = rStream.GetError(); if (pData) { - if (nError) - delete pData; - else - pCollection->Insert( pData); + if (!nError) + pCollection->Insert( pData.release() ); } else nError = errOutOfMemory; diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx index 5dc09a3d9c66..411f88beb1cb 100644 --- a/sc/source/ui/unoobj/funcuno.cxx +++ b/sc/source/ui/unoobj/funcuno.cxx @@ -45,6 +45,7 @@ #include "dociter.hxx" #include "stringutil.hxx" #include "tokenarray.hxx" +#include <memory> using namespace com::sun::star; @@ -148,12 +149,12 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, rSrcRange.aEnd.Row() - rSrcRange.aStart.Row() + rDestPos.Row(), nDestTab ) ); - ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); + std::unique_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP )); ScMarkData aSourceMark; aSourceMark.SelectOneTable( nSrcTab ); // for CopyToClip aSourceMark.SetMarkArea( rSrcRange ); ScClipParam aClipParam(rSrcRange, false); - pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aSourceMark); + pSrcDoc->CopyToClip(aClipParam, pClipDoc.get(), &aSourceMark); if ( pClipDoc->HasAttrib( 0,0,nSrcTab, MAXCOL,MAXROW,nSrcTab, HASATTR_MERGED | HASATTR_OVERLAPPED ) ) @@ -167,9 +168,8 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, ScMarkData aDestMark; aDestMark.SelectOneTable( nDestTab ); aDestMark.SetMarkArea( aNewRange ); - pDestDoc->CopyFromClip( aNewRange, aDestMark, InsertDeleteFlags::ALL & ~InsertDeleteFlags::FORMULA, nullptr, pClipDoc, false ); + pDestDoc->CopyFromClip( aNewRange, aDestMark, InsertDeleteFlags::ALL & ~InsertDeleteFlags::FORMULA, nullptr, pClipDoc.get(), false ); - delete pClipDoc; return true; } diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index 35aa32b13e28..b820606c399f 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -26,6 +26,7 @@ #include <rtl/math.hxx> #include <sal/macros.h> #include <algorithm> +#include <memory> #include "analysishelper.hxx" #include "analysis.hrc" @@ -746,14 +747,12 @@ OUString ConvertFromDec( double fNum, double fMin, double fMax, sal_uInt16 nBase else if( ( bNeg && nLen < nMaxPlaces ) || ( !bNeg && nLen < nPlaces ) ) { sal_Int32 nLeft = nPlaces - nLen; - sal_Char* p = new sal_Char[ nLeft + 1 ]; - memset( p, bNeg? GetMaxChar( nBase ) : '0', nLeft ); + std::unique_ptr<sal_Char[]> p( new sal_Char[ nLeft + 1 ] ); + memset( p.get(), bNeg ? GetMaxChar( nBase ) : '0', nLeft ); p[ nLeft ] = 0x00; - OUString aTmp( p, nLeft, RTL_TEXTENCODING_MS_1252 ); + OUString aTmp( p.get(), nLeft, RTL_TEXTENCODING_MS_1252 ); aTmp += aRet; aRet = aTmp; - - delete[] p; } } diff --git a/sd/source/filter/eppt/eppt.cxx b/sd/source/filter/eppt/eppt.cxx index 6f50c98848ed..a272f8263e55 100644 --- a/sd/source/filter/eppt/eppt.cxx +++ b/sd/source/filter/eppt/eppt.cxx @@ -54,6 +54,7 @@ #include <oox/export/utils.hxx> #include <oox/ole/olehelper.hxx> #include <rtl/math.hxx> +#include <memory> #include <sfx2/objsh.hxx> // complete SfxObjectShell for SaveVBA under -fsanitize=function @@ -1447,10 +1448,9 @@ extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL ExportPPT( const std::vector< SvMemoryStream* pVBA, sal_uInt32 nCnvrtFlags ) { - PPTWriter* pPPTWriter = new PPTWriter( rSvStorage, rXModel, rXStatInd, pVBA, nCnvrtFlags ); + std::unique_ptr<PPTWriter> pPPTWriter(new PPTWriter( rSvStorage, rXModel, rXStatInd, pVBA, nCnvrtFlags )); pPPTWriter->exportPPT(rMediaData); bool bStatus = pPPTWriter->IsValid(); - delete pPPTWriter; return bStatus; } diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index 4d716e740dc1..820408c7fcee 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -2743,11 +2743,8 @@ ImplSdPPTImport::ReadFormControl( tools::SvRef<SotStorage>& rSrc1, css::uno::Ref extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL ImportPPT( SdDrawDocument* pDocument, SvStream& rDocStream, SotStorage& rStorage, SfxMedium& rMedium ) { - SdPPTImport* pImport = new SdPPTImport( pDocument, rDocStream, rStorage, rMedium ); + std::unique_ptr<SdPPTImport> pImport( new SdPPTImport( pDocument, rDocStream, rStorage, rMedium )); bool bRet = pImport->Import(); - - delete pImport; - return bRet; } 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; diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index 5e1584e4cfba..74e17f87c118 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -203,10 +203,10 @@ namespace { const size_t nOrigLen(sal::static_int_cast<size_t>(i_rStr.getLength())); const sal_Char* const pOrig(i_rStr.getStr()); - sal_Char* const pBuffer(new sal_Char[nOrigLen + 1]); + std::unique_ptr<sal_Char[]> pBuffer(new sal_Char[nOrigLen + 1]); const sal_Char* pRead(pOrig); - sal_Char* pWrite(pBuffer); + sal_Char* pWrite(pBuffer.get()); const sal_Char* pCur(pOrig); while ((pCur = strchr(pCur, '\\')) != nullptr) { @@ -237,8 +237,7 @@ namespace } *pWrite = '\0'; - OString aResult(pBuffer); - delete[] pBuffer; + OString aResult(pBuffer.get()); return aResult; } diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx index c81adc331dbf..b67d6613ba42 100644 --- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx @@ -26,6 +26,7 @@ #include <math.h> #include <boost/shared_array.hpp> +#include <memory> #if defined _MSC_VER #pragma warning(push, 1) @@ -309,11 +310,11 @@ void writePpm_( OutputBuffer& o_rOutputBuf, // initialize stream Guchar *p; GfxRGB rgb; - ImageStream* imgStr = + std::unique_ptr<ImageStream> imgStr( new ImageStream(str, width, colorMap->getNumPixelComps(), - colorMap->getBits()); + colorMap->getBits())); imgStr->reset(); for( int y=0; y<height; ++y) @@ -329,9 +330,6 @@ void writePpm_( OutputBuffer& o_rOutputBuf, p +=colorMap->getNumPixelComps(); } } - - delete imgStr; - } // call this only for 1 bit image streams ! diff --git a/slideshow/source/engine/transitions/slidetransitionfactory.cxx b/slideshow/source/engine/transitions/slidetransitionfactory.cxx index e40cd310354f..3e674c397a53 100644 --- a/slideshow/source/engine/transitions/slidetransitionfactory.cxx +++ b/slideshow/source/engine/transitions/slidetransitionfactory.cxx @@ -44,6 +44,7 @@ #include "clippingfunctor.hxx" #include "combtransition.hxx" #include "tools.hxx" +#include <memory> @@ -882,7 +883,7 @@ NumberAnimationSharedPtr createPluginTransition( const SoundPlayerSharedPtr& pSoundPlayer, EventMultiplexer& rEventMultiplexer) { - PluginSlideChange* pTransition = + std::unique_ptr<PluginSlideChange> pTransition( new PluginSlideChange( nTransitionType, nTransitionSubType, @@ -892,13 +893,12 @@ NumberAnimationSharedPtr createPluginTransition( rScreenUpdater, xFactory, pSoundPlayer, - rEventMultiplexer ); + rEventMultiplexer )); if( pTransition->Success() ) - return NumberAnimationSharedPtr( pTransition ); + return NumberAnimationSharedPtr( pTransition.release() ); else { - delete pTransition; return NumberAnimationSharedPtr(); } } diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx index 422952a7766b..9fa46c5fc375 100644 --- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx @@ -46,6 +46,7 @@ #include <vector> #include <numeric> #include <algorithm> +#include <memory> #include <comphelper/processfactory.hxx> #include <com/sun/star/i18n/BreakIterator.hpp> #include <com/sun/star/i18n/ScriptType.hpp> @@ -268,7 +269,7 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F const SvxCharScaleWidthItem& rCharScaleWidthItem = static_cast<const SvxCharScaleWidthItem&>(pCustomShape->GetMergedItem( EE_CHAR_FONTWIDTH )); sal_uInt16 nCharScaleWidth = rCharScaleWidthItem.GetValue(); - long* pDXArry = nullptr; + std::unique_ptr<long[]> pDXArry; sal_Int32 nWidth = 0; // VERTICAL @@ -282,7 +283,7 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F { FWCharacterData aCharacterData; OUString aCharText( (sal_Unicode)rText[ i ] ); - if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, aCharText, 0, 0, -1, true, nWidth, pDXArry ) ) + if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, aCharText, 0, 0, -1, true, nWidth, pDXArry.get() ) ) { sal_Int32 nTextWidth = pVirDev->GetTextWidth( aCharText); std::vector< tools::PolyPolygon >::iterator aOutlineIter = aCharacterData.vOutlines.begin(); @@ -333,19 +334,18 @@ void GetTextAreaOutline( const FWData& rFWData, const SdrObject* pCustomShape, F { if ( ( nCharScaleWidth != 100 ) && nCharScaleWidth ) { // applying character spacing - pDXArry = new long[ rText.getLength() ]; - pVirDev->GetTextArray( rText, pDXArry); + pDXArry.reset(new long[ rText.getLength() ]); + pVirDev->GetTextArray( rText, pDXArry.get()); FontMetric aFontMetric( pVirDev->GetFontMetric() ); aFont.SetWidth( (sal_Int32)( (double)aFontMetric.GetWidth() * ( (double)100 / (double)nCharScaleWidth ) ) ); pVirDev->SetFont( aFont ); } FWCharacterData aCharacterData; - if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, rText, 0, 0, -1, true, nWidth, pDXArry ) ) + if ( pVirDev->GetTextOutlines( aCharacterData.vOutlines, rText, 0, 0, -1, true, nWidth, pDXArry.get() ) ) { aParagraphIter->vCharacters.push_back( aCharacterData ); } } - delete[] pDXArry; // vertical alignment std::vector< FWCharacterData >::iterator aCharacterIter( aParagraphIter->vCharacters.begin() ); diff --git a/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx b/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx index 9b20d35b4901..161986f2f17a 100644 --- a/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx @@ -20,6 +20,7 @@ #include "svx/EnhancedCustomShapeTypeNames.hxx" #include <osl/mutex.hxx> #include <unordered_map> +#include <memory> typedef std::unordered_map< const char*, MSO_SPT, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap; @@ -288,12 +289,11 @@ MSO_SPT EnhancedCustomShapeTypeNames::Get( const OUString& rShapeType ) } MSO_SPT eRetValue = mso_sptNil; int i, nLen = rShapeType.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)rShapeType[ 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; @@ -544,12 +544,11 @@ OUString EnhancedCustomShapeTypeNames::GetAccName( const OUString& rShapeType ) } OUString sRetValue; int i, nLen = rShapeType.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)rShapeType[ i ]; pBuf[ i ] = 0; - TypeACCNameHashMap::iterator aHashIter( pACCHashMap->find( pBuf ) ); - delete[] pBuf; + TypeACCNameHashMap::iterator aHashIter( pACCHashMap->find( pBuf.get() ) ); if ( aHashIter != pACCHashMap->end() ) sRetValue = OUString::createFromAscii( (*aHashIter).second ); return sRetValue; diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 5fce21744cc1..578af2c3ecc5 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -51,6 +51,7 @@ #include <statstr.hrc> #include <redline.hxx> #include <txatbase.hxx> +#include <memory> using namespace ::com::sun::star::i18n; @@ -748,14 +749,14 @@ static sal_uLong lcl_FindSelection( SwFindParas& rParas, SwCursor* pCurCrsr, // only create progress bar for ShellCrsr bool bIsUnoCrsr = dynamic_cast<SwUnoCrsr*>(pCurCrsr) != nullptr; - _PercentHdl* pPHdl = nullptr; + std::unique_ptr<_PercentHdl> pPHdl; sal_uInt16 nCrsrCnt = 0; if( FND_IN_SEL & eFndRngs ) { while( pCurCrsr != ( pTmpCrsr = pTmpCrsr->GetNext() )) ++nCrsrCnt; if( nCrsrCnt && !bIsUnoCrsr ) - pPHdl = new _PercentHdl( 0, nCrsrCnt, pDoc->GetDocShell() ); + pPHdl.reset(new _PercentHdl( 0, nCrsrCnt, pDoc->GetDocShell() )); } else pSaveCrsr = static_cast<SwPaM*>(pSaveCrsr->GetPrev()); @@ -773,7 +774,7 @@ static sal_uLong lcl_FindSelection( SwFindParas& rParas, SwCursor* pCurCrsr, aRegion.Exchange(); if( !nCrsrCnt && !pPHdl && !bIsUnoCrsr ) - pPHdl = new _PercentHdl( aRegion ); + pPHdl.reset(new _PercentHdl( aRegion )); // as long as found and not at same position while( *pSttPos <= *pEndPos && @@ -854,7 +855,6 @@ static sal_uLong lcl_FindSelection( SwFindParas& rParas, SwCursor* pCurCrsr, if( nFound && !pFndRing ) // if no ring should be created pFndRing = pCurCrsr->Create(); - delete pPHdl; pDoc->GetIDocumentUndoRedo().DoUndo(bDoesUndo); return nFound; } diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index ec341ecda61c..f7897d7539aa 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -73,6 +73,7 @@ #include <svx/svdouno.hxx> #include <editeng/formatbreakitem.hxx> #include <com/sun/star/i18n/Boundary.hpp> +#include <memory> using namespace ::com::sun::star::i18n; @@ -294,7 +295,7 @@ namespace { SwDoc* pDestDoc = rCpyPam.GetDoc(); SwPosition* pCpyStt = rCpyPam.Start(), *pCpyEnd = rCpyPam.End(); - SwPaM* pDelPam = nullptr; + std::unique_ptr<SwPaM> pDelPam; const SwPosition *pStt = rPam.Start(), *pEnd = rPam.End(); // We have to count the "non-copied" nodes sal_uLong nDelCount = 0; @@ -325,7 +326,7 @@ namespace default: { - pDelPam = new SwPaM( *pCpyStt, pDelPam ); + pDelPam.reset(new SwPaM( *pCpyStt, pDelPam.get() )); if( *pStt < *pRStt ) { lcl_NonCopyCount( rPam, aCorrIdx, pRStt->nNode.GetIndex(), nDelCount ); @@ -360,7 +361,6 @@ namespace break; delete pDelPam->GetNext(); } while( true ); - delete pDelPam; pDestDoc->getIDocumentRedlineAccess().SetRedlineMode_intern( eOld ); } diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx index 6b2eac765d70..6b9ef815b1a2 100644 --- a/sw/source/core/docnode/node.cxx +++ b/sw/source/core/docnode/node.cxx @@ -66,6 +66,7 @@ #include <IDocumentLayoutAccess.hxx> #include <calbck.hxx> #include "ndole.hxx" +#include <memory> using namespace ::com::sun::star::i18n; @@ -149,10 +150,10 @@ bool Put( std::shared_ptr<const SfxItemSet>& rpAttrSet, const SwContentNode& rNo SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) ); // #i76273# Robust - SfxItemSet* pStyleNames = nullptr; + std::unique_ptr<SfxItemSet> pStyleNames; if ( SfxItemState::SET == rSet.GetItemState( RES_FRMATR_STYLE_NAME, false ) ) { - pStyleNames = new SfxItemSet( *aNewSet.GetPool(), RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME ); + pStyleNames.reset(new SfxItemSet( *aNewSet.GetPool(), RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME )); pStyleNames->Put( aNewSet ); } @@ -162,7 +163,6 @@ bool Put( std::shared_ptr<const SfxItemSet>& rpAttrSet, const SwContentNode& rNo if ( pStyleNames ) { aNewSet.Put( *pStyleNames ); - delete pStyleNames; } if ( bRet ) @@ -197,10 +197,10 @@ bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet, SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) ); // #i76273# Robust - SfxItemSet* pStyleNames = nullptr; + std::unique_ptr<SfxItemSet> pStyleNames; if ( SfxItemState::SET == rSet.GetItemState( RES_FRMATR_STYLE_NAME, false ) ) { - pStyleNames = new SfxItemSet( *aNewSet.GetPool(), RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME ); + pStyleNames.reset(new SfxItemSet( *aNewSet.GetPool(), RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME )); pStyleNames->Put( aNewSet ); } @@ -215,7 +215,6 @@ bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet, if ( pStyleNames ) { aNewSet.Put( *pStyleNames ); - delete pStyleNames; } if ( bRet ) diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx index 9831eec9d2be..d96b397df9a6 100644 --- a/sw/source/core/docnode/swbaslnk.cxx +++ b/sw/source/core/docnode/swbaslnk.cxx @@ -51,6 +51,7 @@ #include <cntfrm.hxx> #include <htmltbl.hxx> #include <calbck.hxx> +#include <memory> using namespace com::sun::star; @@ -292,9 +293,9 @@ static bool SetGrfFlySize( const Size& rGrfSz, SwGrfNode* pGrfNd, const Size& rO { bool bRet = false; SwViewShell *pSh = pGrfNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell(); - CurrShell *pCurr = nullptr; + std::unique_ptr<CurrShell> pCurr; if ( pGrfNd->GetDoc()->GetEditShell() ) - pCurr = new CurrShell( pSh ); + pCurr.reset(new CurrShell( pSh )); Size aSz = rOrigGrfSize; if ( !(aSz.Width() && aSz.Height()) && @@ -366,8 +367,6 @@ static bool SetGrfFlySize( const Size& rGrfSz, SwGrfNode* pGrfNd, const Size& rO pGrfNd->SetTwipSize( rGrfSz ); } - delete pCurr; - return bRet; } diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx index ae6065c2f94d..098be6bf7132 100644 --- a/sw/source/core/frmedt/tblsel.cxx +++ b/sw/source/core/frmedt/tblsel.cxx @@ -48,6 +48,7 @@ #include <frmtool.hxx> #include <calbck.hxx> #include <deque> +#include <memory> // see also swtable.cxx #define COLFUZZY 20L @@ -2036,14 +2037,13 @@ static void lcl_InsertRow( SwTableLine &rLine, SwLayoutFrm *pUpper, SwFrm *pSibl static void _FndBoxCopyCol( SwTableBox* pBox, _FndPara* pFndPara ) { - _FndBox* pFndBox = new _FndBox( pBox, pFndPara->pFndLine ); + std::unique_ptr<_FndBox> pFndBox(new _FndBox( pBox, pFndPara->pFndLine )); if( pBox->GetTabLines().size() ) { - _FndPara aPara( *pFndPara, pFndBox ); + _FndPara aPara( *pFndPara, pFndBox.get() ); ForEach_FndLineCopyCol( pFndBox->GetBox()->GetTabLines(), &aPara ); if( pFndBox->GetLines().empty() ) { - delete pFndBox; return; } } @@ -2051,11 +2051,10 @@ static void _FndBoxCopyCol( SwTableBox* pBox, _FndPara* pFndPara ) { if( pFndPara->rBoxes.find( pBox ) == pFndPara->rBoxes.end()) { - delete pFndBox; return; } } - pFndPara->pFndLine->GetBoxes().push_back(std::unique_ptr<_FndBox>(pFndBox)); + pFndPara->pFndLine->GetBoxes().push_back( std::move(pFndBox) ); } static void _FndLineCopyCol( SwTableLine* pLine, _FndPara* pFndPara ) diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx index 1c4f3961d2d7..150fbc0acbdb 100644 --- a/sw/source/core/table/swnewtable.cxx +++ b/sw/source/core/table/swnewtable.cxx @@ -1328,7 +1328,7 @@ static sal_uInt16 lcl_CalculateSplitLineHeights( SwSplitLines &rCurr, SwSplitLin } SwTwips nHeight = 0; - SwTwips* pLines = new SwTwips[ nLast + 1 - nFirst ]; + std::unique_ptr<SwTwips[]> pLines(new SwTwips[ nLast + 1 - nFirst ]); for( sal_uInt16 i = nFirst; i <= nLast; ++i ) { bool bLayoutAvailable = false; @@ -1349,7 +1349,6 @@ static sal_uInt16 lcl_CalculateSplitLineHeights( SwSplitLines &rCurr, SwSplitLin } ++pSplit; } - delete[] pLines; return nFirst; } diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx index d4f18ed048f3..2d9cc7a37e71 100644 --- a/sw/source/core/text/itradj.cxx +++ b/sw/source/core/text/itradj.cxx @@ -30,6 +30,7 @@ #include "pordrop.hxx" #include "pormulti.hxx" #include <portab.hxx> +#include <memory> #define MIN_TAB_WIDTH 60 @@ -128,9 +129,9 @@ static bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTextSizeInfo& rInf, // kashida positions found in SwScriptInfo are not necessarily valid in every font // if two characters are replaced by a ligature glyph, there will be no place for a kashida - sal_Int32* pKashidaPos = new sal_Int32[ rKashidas ]; - sal_Int32* pKashidaPosDropped = new sal_Int32[ rKashidas ]; - rSI.GetKashidaPositions ( nIdx, rItr.GetLength(), pKashidaPos ); + std::unique_ptr<sal_Int32[]> pKashidaPos( new sal_Int32[ rKashidas ] ); + std::unique_ptr<sal_Int32[]> pKashidaPosDropped( new sal_Int32[ rKashidas ] ); + rSI.GetKashidaPositions ( nIdx, rItr.GetLength(), pKashidaPos.get() ); sal_Int32 nKashidaIdx = 0; while ( rKashidas && nIdx < nEnd ) { @@ -151,8 +152,6 @@ static bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTextSizeInfo& rInf, // Kashida glyph looks suspicious, skip Kashida justification if ( rInf.GetOut()->GetMinKashida() <= 0 ) { - delete[] pKashidaPos; - delete[] pKashidaPosDropped; return false; } @@ -167,12 +166,12 @@ static bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTextSizeInfo& rInf, ComplexTextLayoutMode nOldLayout = rInf.GetOut()->GetLayoutMode(); rInf.GetOut()->SetLayoutMode ( nOldLayout | TEXT_LAYOUT_BIDI_RTL ); nKashidasDropped = rInf.GetOut()->ValidateKashidas ( rInf.GetText(), nIdx, nNext - nIdx, - nKashidasInAttr, pKashidaPos + nKashidaIdx, - pKashidaPosDropped ); + nKashidasInAttr, pKashidaPos.get() + nKashidaIdx, + pKashidaPosDropped.get() ); rInf.GetOut()->SetLayoutMode ( nOldLayout ); if ( nKashidasDropped ) { - rSI.MarkKashidasInvalid(nKashidasDropped, pKashidaPosDropped); + rSI.MarkKashidasInvalid(nKashidasDropped, pKashidaPosDropped.get()); rKashidas -= nKashidasDropped; nGluePortion -= nKashidasDropped; } @@ -181,8 +180,6 @@ static bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTextSizeInfo& rInf, } nIdx = nNext; } - delete[] pKashidaPos; - delete[] pKashidaPosDropped; // return false if all kashidas have been eliminated return (rKashidas > 0); diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 17c67ffa5954..8763a8304946 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -21,6 +21,7 @@ #include <map> #include <algorithm> +#include <memory> #include <com/sun/star/beans/PropertyState.hpp> #include <com/sun/star/embed/ElementModes.hpp> @@ -955,7 +956,7 @@ void InsertFile(SwUnoCrsr* pUnoCrsr, const OUString& rURL, throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException, std::exception) { - SfxMedium* pMed = nullptr; + std::unique_ptr<SfxMedium> pMed; SwDoc* pDoc = pUnoCrsr->GetDoc(); SwDocShell* pDocSh = pDoc->GetDocShell(); utl::MediaDescriptor aMediaDescriptor( rOptions ); @@ -1003,43 +1004,39 @@ void InsertFile(SwUnoCrsr* pUnoCrsr, const OUString& rURL, { if( xInputStream.is() && !xReadStorage.is()) { - pMed = new SfxMedium; + pMed.reset(new SfxMedium); pMed->setStreamToLoadFrom(xInputStream, true ); } else - pMed = xReadStorage.is() ? + pMed.reset(xReadStorage.is() ? new SfxMedium(xReadStorage, sBaseURL, nullptr ) : - new SfxMedium(sFileName, StreamMode::READ, nullptr, nullptr ); + new SfxMedium(sFileName, StreamMode::READ, nullptr, nullptr )); if( !sBaseURL.isEmpty() ) pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) ); SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() ); ErrCode nErr = aMatcher.GuessFilter(*pMed, &pFilter, SfxFilterFlags::NONE); if ( nErr || !pFilter) - DELETEZ(pMed); - else - pMed->SetFilter( pFilter ); + return; + pMed->SetFilter( pFilter ); } else { - if(!pMed) + if( xInputStream.is() && !xReadStorage.is()) + { + pMed.reset(new SfxMedium); + pMed->setStreamToLoadFrom(xInputStream, true ); + pMed->SetFilter( pFilter ); + } + else { - if( xInputStream.is() && !xReadStorage.is()) + if( xReadStorage.is() ) { - pMed = new SfxMedium; - pMed->setStreamToLoadFrom(xInputStream, true ); + pMed.reset(new SfxMedium(xReadStorage, sBaseURL, nullptr )); pMed->SetFilter( pFilter ); } else - { - if( xReadStorage.is() ) - { - pMed = new SfxMedium(xReadStorage, sBaseURL, nullptr ); - pMed->SetFilter( pFilter ); - } - else - pMed = new SfxMedium(sFileName, StreamMode::READ, pFilter, nullptr); - } + pMed.reset(new SfxMedium(sFileName, StreamMode::READ, pFilter, nullptr)); } if(!sFilterOptions.isEmpty()) pMed->GetItemSet()->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, sFilterOptions ) ); @@ -1047,9 +1044,6 @@ void InsertFile(SwUnoCrsr* pUnoCrsr, const OUString& rURL, pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) ); } - if( !pMed ) - return; - // this sourcecode is not responsible for the lifetime of the shell, SfxObjectShellLock should not be used SfxObjectShellRef aRef( pDocSh ); @@ -1091,7 +1085,6 @@ void InsertFile(SwUnoCrsr* pUnoCrsr, const OUString& rURL, } } - delete pMed; } // insert text and scan for CR characters in order to insert diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 24134bf53801..20de3d335ecd 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1944,14 +1944,14 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, throw lang::IllegalArgumentException(); SfxItemSet& rStyleSet = rBase.GetItemSet(); - SwFormatPageDesc* pNewDesc = nullptr; + std::unique_ptr<SwFormatPageDesc> pNewDesc; const SfxPoolItem* pItem; if(SfxItemState::SET == rStyleSet.GetItemState( RES_PAGEDESC, true, &pItem ) ) { - pNewDesc = new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem)); + pNewDesc.reset( new SwFormatPageDesc(*static_cast<const SwFormatPageDesc*>(pItem)) ); } - if(!pNewDesc) - pNewDesc = new SwFormatPageDesc(); + else + pNewDesc.reset( new SwFormatPageDesc ); OUString uDescName; aValue >>= uDescName; OUString sDescName; @@ -1981,7 +1981,6 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, rStyleSet.Put(*pNewDesc); } - delete pNewDesc; bDone = true; break; } @@ -2126,12 +2125,12 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, if(aValue >>= sTmp) { SfxItemSet& rStyleSet = rBase.GetItemSet(); - SwFormatRuby* pRuby = nullptr; + std::unique_ptr<SwFormatRuby> pRuby; const SfxPoolItem* pItem; if(SfxItemState::SET == rStyleSet.GetItemState( RES_TXTATR_CJK_RUBY, true, &pItem ) ) - pRuby = new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem)); - if(!pRuby) - pRuby = new SwFormatRuby(OUString()); + pRuby.reset(new SwFormatRuby(*static_cast<const SwFormatRuby*>(pItem))); + else + pRuby.reset(new SwFormatRuby(OUString())); OUString sStyle; SwStyleNameMapper::FillUIName(sTmp, sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); pRuby->SetCharFormatName( sTmp ); @@ -2142,7 +2141,6 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, pRuby->SetCharFormatId(nId); } rStyleSet.Put(*pRuby); - delete pRuby; } else throw lang::IllegalArgumentException(); @@ -2157,12 +2155,12 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, { SfxItemSet& rStyleSet = rBase.GetItemSet(); - SwFormatDrop* pDrop = nullptr; + std::unique_ptr<SwFormatDrop> pDrop; const SfxPoolItem* pItem; if(SfxItemState::SET == rStyleSet.GetItemState( RES_PARATR_DROP, true, &pItem ) ) - pDrop = new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem)); - if(!pDrop) - pDrop = new SwFormatDrop(); + pDrop.reset(new SwFormatDrop(*static_cast<const SwFormatDrop*>(pItem))); + else + pDrop.reset( new SwFormatDrop ); OUString uStyle; aValue >>= uStyle; OUString sStyle; @@ -2174,7 +2172,6 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, else throw lang::IllegalArgumentException(); rStyleSet.Put(*pDrop); - delete pDrop; } else throw lang::IllegalArgumentException(); diff --git a/sw/source/filter/html/htmlforw.cxx b/sw/source/filter/html/htmlforw.cxx index 37a8a73ee162..4388f16d093f 100644 --- a/sw/source/filter/html/htmlforw.cxx +++ b/sw/source/filter/html/htmlforw.cxx @@ -63,6 +63,7 @@ #include "htmlform.hxx" #include "frmfmt.hxx" #include <rtl/strbuf.hxx> +#include <memory> using namespace ::com::sun::star; @@ -1292,15 +1293,14 @@ static void AddControl( HTMLControls& rControls, if( xForm.is() ) { uno::Reference< container::XIndexContainer > xFormComps( xForm, uno::UNO_QUERY ); - HTMLControl *pHCntrl = new HTMLControl( xFormComps, nNodeIdx ); - HTMLControls::const_iterator it = rControls.find( pHCntrl ); + std::unique_ptr<HTMLControl> pHCntrl(new HTMLControl( xFormComps, nNodeIdx )); + HTMLControls::const_iterator it = rControls.find( pHCntrl.get() ); if( it == rControls.end() ) - rControls.insert( pHCntrl ); + rControls.insert( pHCntrl.release() ); else { if( (*it)->xFormComps==xFormComps ) (*it)->nCount++; - delete pHCntrl; } } } diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx index 701415844a5e..961cd9de1b1c 100644 --- a/testtools/source/bridgetest/bridgetest.cxx +++ b/testtools/source/bridgetest/bridgetest.cxx @@ -51,6 +51,7 @@ #include "currentcontextchecker.hxx" #include "multi.hxx" +#include <memory> using namespace osl; using namespace cppu; @@ -1043,8 +1044,8 @@ uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type) reinterpret_cast<typelib_IndirectTypeDescription*>(pTdRaw); typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType; - sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements]; - sal_Int8* pBufCur = buf; + std::unique_ptr<sal_Int8[]> buf(new sal_Int8[pTdElem->nSize * val->nElements]); + sal_Int8* pBufCur = buf.get(); uno_Sequence* retSeq = nullptr; switch (pTdElem->eTypeClass) @@ -1070,7 +1071,6 @@ uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type) val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire)); break; } - delete[] buf; return retSeq; } diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx index 6a817ee967c1..d4004c79c544 100644 --- a/tools/source/inet/inetmime.cxx +++ b/tools/source/inet/inetmime.cxx @@ -19,6 +19,7 @@ #include <cstddef> #include <limits> +#include <memory> #include <osl/diagnose.h> #include <rtl/alloc.h> @@ -537,11 +538,10 @@ void appendISO88591(OUString & rText, sal_Char const * pBegin, sal_Char const * pEnd) { sal_Int32 nLength = pEnd - pBegin; - sal_Unicode * pBuffer = new sal_Unicode[nLength]; - for (sal_Unicode * p = pBuffer; pBegin != pEnd;) + std::unique_ptr<sal_Unicode[]> pBuffer(new sal_Unicode[nLength]); + for (sal_Unicode * p = pBuffer.get(); pBegin != pEnd;) *p++ = static_cast<unsigned char>(*pBegin++); - rText += OUString(pBuffer, nLength); - delete[] pBuffer; + rText += OUString(pBuffer.get(), nLength); } // INetMIMECharsetList_Impl diff --git a/ucb/source/ucp/webdav-neon/LockSequence.cxx b/ucb/source/ucp/webdav-neon/LockSequence.cxx index 8d57e764d83d..60808f945bf3 100644 --- a/ucb/source/ucp/webdav-neon/LockSequence.cxx +++ b/ucb/source/ucp/webdav-neon/LockSequence.cxx @@ -31,14 +31,11 @@ #include <ne_xml.h> #include <osl/diagnose.h> #include "LockSequence.hxx" +#include <memory> using namespace webdav_ucp; using namespace com::sun::star; -#define BEEHIVE_BUGS_WORKAROUND - - - struct LockSequenceParseContext { ucb::Lock * pLock; @@ -130,11 +127,7 @@ extern "C" int LockSequence_startelement_callback( extern "C" int LockSequence_chardata_callback( void *userdata, int state, -#ifdef BEEHIVE_BUGS_WORKAROUND - const char *buf1, -#else const char *buf, -#endif size_t len ) { LockSequenceParseContext * pCtx @@ -142,15 +135,10 @@ extern "C" int LockSequence_chardata_callback( if ( !pCtx->pLock ) pCtx->pLock = new ucb::Lock; -#ifdef BEEHIVE_BUGS_WORKAROUND // Beehive sends XML values containing trailing newlines. - if ( buf1[ len - 1 ] == 0x0a ) + if ( buf[ len - 1 ] == 0x0a ) len--; - char * buf = new char[ len + 1 ](); - strncpy( buf, buf1, len ); -#endif - switch ( state ) { case STATE_DEPTH: @@ -237,10 +225,6 @@ extern "C" int LockSequence_chardata_callback( } -#ifdef BEEHIVE_BUGS_WORKAROUND - delete [] buf; -#endif - return 0; // zero to continue, non-zero to abort parsing } diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx index e281498f3fc3..6095ff38fdfb 100644 --- a/vcl/source/gdi/dibtools.cxx +++ b/vcl/source/gdi/dibtools.cxx @@ -797,7 +797,7 @@ bool ImplReadDIBBody( SvStream& rIStm, Bitmap& rBmp, Bitmap* pBmpAlpha, sal_uLon sal_uInt16 nColors(0); SvStream* pIStm; - SvMemoryStream* pMemStm = nullptr; + std::unique_ptr<SvMemoryStream> pMemStm; sal_uInt8* pData = nullptr; if (aHeader.nBitCount <= 8) @@ -834,7 +834,8 @@ bool ImplReadDIBBody( SvStream& rIStm, Bitmap& rBmp, Bitmap* pBmpAlpha, sal_uLon // set decoded bytes to memory stream, // from which we will read the bitmap data - pIStm = pMemStm = new SvMemoryStream; + pMemStm.reset( new SvMemoryStream); + pIStm = pMemStm.get(); pMemStm->SetBuffer( pData, nUncodedSize, false, nUncodedSize ); nOffset = 0; } @@ -880,7 +881,6 @@ bool ImplReadDIBBody( SvStream& rIStm, Bitmap& rBmp, Bitmap* pBmpAlpha, sal_uLon rtl_freeMemory(pData); } - delete pMemStm; Bitmap::ReleaseAccess(pAcc); if(bAlphaPossible) diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index c7b8e35657df..51fb545b7323 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -18,6 +18,7 @@ */ #include <rtl/crc.h> +#include <memory> #include <tools/stream.hxx> #include <tools/vcompat.hxx> #include <tools/fract.hxx> @@ -2753,19 +2754,15 @@ SvStream& ReadGDIMetaFile( SvStream& rIStm, GDIMetaFile& rGDIMetaFile ) if ( !strcmp( aId, "VCLMTF" ) ) { // new format - VersionCompat* pCompat; sal_uInt32 nStmCompressMode = 0; sal_uInt32 nCount = 0; - - pCompat = new VersionCompat( rIStm, StreamMode::READ ); + std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rIStm, StreamMode::READ )); rIStm.ReadUInt32( nStmCompressMode ); ReadMapMode( rIStm, rGDIMetaFile.aPrefMapMode ); ReadPair( rIStm, rGDIMetaFile.aPrefSize ); rIStm.ReadUInt32( nCount ); - delete pCompat; - ImplMetaReadData aReadData; aReadData.meActualCharSet = rIStm.GetStreamCharSet(); diff --git a/vcl/source/gdi/gfxlink.cxx b/vcl/source/gdi/gfxlink.cxx index cab29181f625..1756a0332d6e 100644 --- a/vcl/source/gdi/gfxlink.cxx +++ b/vcl/source/gdi/gfxlink.cxx @@ -252,7 +252,7 @@ bool GfxLink::ExportNative( SvStream& rOStream ) const SvStream& WriteGfxLink( SvStream& rOStream, const GfxLink& rGfxLink ) { - VersionCompat* pCompat = new VersionCompat( rOStream, StreamMode::WRITE, 2 ); + std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStream, StreamMode::WRITE, 2 )); // Version 1 rOStream.WriteUInt16( rGfxLink.GetType() ).WriteUInt32( rGfxLink.GetDataSize() ).WriteUInt32( rGfxLink.GetUserId() ); @@ -261,8 +261,6 @@ SvStream& WriteGfxLink( SvStream& rOStream, const GfxLink& rGfxLink ) WritePair( rOStream, rGfxLink.GetPrefSize() ); WriteMapMode( rOStream, rGfxLink.GetPrefMapMode() ); - delete pCompat; - if( rGfxLink.GetDataSize() ) { if( rGfxLink.IsSwappedOut() ) @@ -283,7 +281,7 @@ SvStream& ReadGfxLink( SvStream& rIStream, GfxLink& rGfxLink) sal_uInt16 nType; sal_uInt8* pBuf; bool bMapAndSizeValid( false ); - VersionCompat* pCompat = new VersionCompat( rIStream, StreamMode::READ ); + std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rIStream, StreamMode::READ )); // Version 1 rIStream.ReadUInt16( nType ).ReadUInt32( nSize ).ReadUInt32( nUserId ); @@ -295,8 +293,6 @@ SvStream& ReadGfxLink( SvStream& rIStream, GfxLink& rGfxLink) bMapAndSizeValid = true; } - delete pCompat; - pBuf = new sal_uInt8[ nSize ]; rIStream.Read( pBuf, nSize ); diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 4d3f9875b557..4a2b59d829b7 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1446,11 +1446,9 @@ SvStream& ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic ) { Graphic aGraphic; GfxLink aLink; - VersionCompat* pCompat; // read compat info - pCompat = new VersionCompat( rIStm, StreamMode::READ ); - delete pCompat; + std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rIStm, StreamMode::READ )); ReadGfxLink( rIStm, aLink ); @@ -1586,14 +1584,11 @@ SvStream& WriteImpGraphic( SvStream& rOStm, const ImpGraphic& rImpGraphic ) ( rOStm.GetCompressMode() & SvStreamCompressFlags::NATIVE ) && rImpGraphic.mpGfxLink && rImpGraphic.mpGfxLink->IsNative() ) { - VersionCompat* pCompat; - // native format rOStm.WriteUInt32( NATIVE_FORMAT_50 ); // write compat info - pCompat = new VersionCompat( rOStm, StreamMode::WRITE, 1 ); - delete pCompat; + std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStm, StreamMode::WRITE, 1 )); rImpGraphic.mpGfxLink->SetPrefMapMode( rImpGraphic.ImplGetPrefMapMode() ); rImpGraphic.mpGfxLink->SetPrefSize( rImpGraphic.ImplGetPrefSize() ); diff --git a/vcl/source/gdi/salmisc.cxx b/vcl/source/gdi/salmisc.cxx index a28c4b0fd51b..6141b2aae55e 100644 --- a/vcl/source/gdi/salmisc.cxx +++ b/vcl/source/gdi/salmisc.cxx @@ -378,27 +378,23 @@ BitmapBuffer* StretchAndConvert( if( bFastConvert ) return pDstBuffer; - Scanline* pSrcScan = nullptr; - Scanline* pDstScan = nullptr; - long* pMapX = nullptr; - long* pMapY = nullptr; + std::unique_ptr<Scanline[]> pSrcScan; + std::unique_ptr<Scanline[]> pDstScan; + std::unique_ptr<long[]> pMapX; + std::unique_ptr<long[]> pMapY; try { - pSrcScan = new Scanline[rSrcBuffer.mnHeight]; - pDstScan = new Scanline[pDstBuffer->mnHeight]; - pMapX = new long[pDstBuffer->mnWidth]; - pMapY = new long[pDstBuffer->mnHeight]; + pSrcScan.reset(new Scanline[rSrcBuffer.mnHeight]); + pDstScan.reset(new Scanline[pDstBuffer->mnHeight]); + pMapX.reset(new long[pDstBuffer->mnWidth]); + pMapY.reset(new long[pDstBuffer->mnHeight]); } catch( const std::bad_alloc& ) { // memory exception, clean up // remark: the buffer ptr causing the exception // is still NULL here - delete[] pSrcScan; - delete[] pDstScan; - delete[] pMapX; - delete[] pMapY; delete pDstBuffer; return nullptr; } @@ -461,30 +457,24 @@ BitmapBuffer* StretchAndConvert( if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 ) { ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, - pSrcScan, pDstScan, pMapX, pMapY ); + pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() ); } else if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 ) { ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, - pSrcScan, pDstScan, pMapX, pMapY ); + pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() ); } else if( rSrcBuffer.mnBitCount > 8 && pDstBuffer->mnBitCount > 8 ) { ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, - pSrcScan, pDstScan, pMapX, pMapY ); + pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() ); } else { ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, - pSrcScan, pDstScan, pMapX, pMapY ); + pSrcScan.get(), pDstScan.get(), pMapX.get(), pMapY.get() ); } - // cleanup - delete[] pSrcScan; - delete[] pDstScan; - delete[] pMapX; - delete[] pMapY; - return pDstBuffer; } diff --git a/xmloff/source/draw/EnhancedCustomShapeToken.cxx b/xmloff/source/draw/EnhancedCustomShapeToken.cxx index 9bcdb8f1aa65..076ae2728fbd 100644 --- a/xmloff/source/draw/EnhancedCustomShapeToken.cxx +++ b/xmloff/source/draw/EnhancedCustomShapeToken.cxx @@ -20,6 +20,7 @@ #include "EnhancedCustomShapeToken.hxx" #include <osl/mutex.hxx> #include <unordered_map> +#include <memory> #include <string.h> namespace xmloff { namespace EnhancedCustomShapeToken { @@ -183,12 +184,11 @@ EnhancedCustomShapeTokenEnum EASGet( const OUString& rShapeType ) } EnhancedCustomShapeTokenEnum eRetValue = EAS_NotFound; int i, nLen = rShapeType.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)rShapeType[ 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; |