diff options
60 files changed, 341 insertions, 436 deletions
diff --git a/codemaker/source/codemaker/exceptiontree.cxx b/codemaker/source/codemaker/exceptiontree.cxx index 0f63a5bd0ab5..e9edd6d8e146 100644 --- a/codemaker/source/codemaker/exceptiontree.cxx +++ b/codemaker/source/codemaker/exceptiontree.cxx @@ -36,14 +36,11 @@ using codemaker::ExceptionTreeNode; ExceptionTreeNode * ExceptionTreeNode::add(rtl::OString const & theName) { std::unique_ptr< ExceptionTreeNode > node(new ExceptionTreeNode(theName)); - children.push_back(node.get()); - return node.release(); + children.push_back(std::move(node)); + return children.back().get(); } void ExceptionTreeNode::clearChildren() { - for (ExceptionTreeNode* child : children) { - delete child; - } children.clear(); } @@ -85,7 +82,7 @@ void ExceptionTree::add( break; } if ((*j)->name == *i) { - node = *j; + node = j->get(); break; } } diff --git a/codemaker/source/cppumaker/cpputype.cxx b/codemaker/source/cppumaker/cpputype.cxx index e3ce8170150b..0be79dca1998 100644 --- a/codemaker/source/cppumaker/cpputype.cxx +++ b/codemaker/source/cppumaker/cpputype.cxx @@ -3405,9 +3405,9 @@ void includeExceptions( if (node->present) { includes.add(node->name); } else { - for (codemaker::ExceptionTreeNode* pChild : node->children) + for (std::unique_ptr<codemaker::ExceptionTreeNode> const & pChild : node->children) { - includeExceptions(includes, pChild); + includeExceptions(includes, pChild.get()); } } } @@ -3759,9 +3759,9 @@ void ServiceType::dumpCatchClauses( out << indent() << "throw;\n"; dec(); } else { - for (codemaker::ExceptionTreeNode* pChild : node->children) + for (std::unique_ptr<codemaker::ExceptionTreeNode> const & pChild : node->children) { - dumpCatchClauses(out, pChild); + dumpCatchClauses(out, pChild.get()); } } } diff --git a/codemaker/source/javamaker/javatype.cxx b/codemaker/source/javamaker/javatype.cxx index 1d414a1d9150..2da2e5f925f2 100644 --- a/codemaker/source/javamaker/javatype.cxx +++ b/codemaker/source/javamaker/javatype.cxx @@ -2087,9 +2087,9 @@ void addExceptionHandlers( if (node->present) { code->addException(start, end, handler, node->name.replace('.', '/')); } else { - for (codemaker::ExceptionTreeNode* p : node->children) + for (std::unique_ptr<codemaker::ExceptionTreeNode> const & p : node->children) { - addExceptionHandlers(p, start, end, handler, code); + addExceptionHandlers(p.get(), start, end, handler, code); } } } diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 82d95e56c45a..155fa0e2b568 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -32,7 +32,8 @@ public: TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - bool VisitCXXDestructorDecl(const CXXDestructorDecl* ); + bool VisitCXXDestructorDecl(const CXXDestructorDecl * ); + bool VisitCompoundStmt(const CompoundStmt * ); }; bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDecl) @@ -130,6 +131,50 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec return true; } +bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt) +{ + if (ignoreLocation(compoundStmt)) + return true; + if (isInUnoIncludeFile(compoundStmt->getLocStart())) + return true; + if (compoundStmt->size() == 0) { + return true; + } + + const CXXDeleteExpr* deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_back()); + if (deleteExpr == nullptr) { + return true; + } + + const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); + if (!pCastExpr) + return true; + const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(pCastExpr->getSubExpr()); + if (!declRefExpr) + return true; + const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + if (!varDecl) + return true; + if (!varDecl->hasInit() || !dyn_cast<CXXNewExpr>(varDecl->getInit())) + return true; + // determine if the var is declared inside the same block as the delete. + // @TODO there should surely be a better way to do this + if (varDecl->getLocStart() < compoundStmt->getLocStart()) + return true; + + report( + DiagnosticsEngine::Warning, + "deleting a local variable at the end of a block, is a sure sign it should be using std::unique_ptr for that var", + deleteExpr->getLocStart()) + << deleteExpr->getSourceRange(); + report( + DiagnosticsEngine::Note, + "var is here", + varDecl->getLocStart()) + << varDecl->getSourceRange(); + return true; +} + loplugin::Plugin::Registration< UseUniquePtr > X("useuniqueptr"); } diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx index 22bfee8183b2..601146730703 100644 --- a/cppcanvas/source/mtfrenderer/emfplus.cxx +++ b/cppcanvas/source/mtfrenderer/emfplus.cxx @@ -2482,8 +2482,8 @@ namespace cppcanvas SAL_INFO("cppcanvas.emf", "EMF+\tglyphs: " << glyphsCount); if( ( optionFlags & 1 ) && glyphsCount > 0 ) { - float *charsPosX = new float[glyphsCount]; - float *charsPosY = new float[glyphsCount]; + std::unique_ptr<float[]> charsPosX( new float[glyphsCount] ); + std::unique_ptr<float[]> charsPosY( new float[glyphsCount] ); OUString text = read_uInt16s_ToOUString(rMF, glyphsCount); @@ -2534,9 +2534,6 @@ namespace cppcanvas rFactoryParms.mrCurrActionIndex += pTextAction->getActionCount()-1; } - - delete[] charsPosX; - delete[] charsPosY; } else { SAL_INFO("cppcanvas.emf", "EMF+\tTODO: fonts (non-unicode glyphs chars)"); } diff --git a/cui/source/dialogs/hltpbase.cxx b/cui/source/dialogs/hltpbase.cxx index f6d48add9a56..10cadbd5b1c3 100644 --- a/cui/source/dialogs/hltpbase.cxx +++ b/cui/source/dialogs/hltpbase.cxx @@ -320,9 +320,9 @@ IMPL_LINK_NOARG(SvxHyperlinkTabPageBase, ClickScriptHdl_Impl, Button*, void) aItem.SetMacroTable( *pMacroTbl ); // create empty itemset for macro-dlg - SfxItemSet* pItemSet = new SfxItemSet(SfxGetpApp()->GetPool(), + std::unique_ptr<SfxItemSet> pItemSet( new SfxItemSet(SfxGetpApp()->GetPool(), SID_ATTR_MACROITEM, - SID_ATTR_MACROITEM ); + SID_ATTR_MACROITEM ) ); pItemSet->Put ( aItem ); /* disable HyperLinkDlg for input while the MacroAssignDlg is working @@ -362,7 +362,6 @@ IMPL_LINK_NOARG(SvxHyperlinkTabPageBase, ClickScriptHdl_Impl, Button*, void) pHyperlinkItem->SetMacroTable( static_cast<const SvxMacroItem*>(pItem)->GetMacroTable() ); } } - delete pItemSet; } } diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index 9d2a82b040d2..664aae7bb451 100644 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -1076,11 +1076,10 @@ void OutlinerView::ApplyBulletsNumbering( const SvxNumberFormat* pNewFmt = aNewRule.Get(nLevel); if (pOldFmt && pNewFmt && (pOldFmt->GetFirstLineOffset() != pNewFmt->GetFirstLineOffset() || pOldFmt->GetAbsLSpace() != pNewFmt->GetAbsLSpace())) { - SvxNumberFormat* pNewFmtClone = new SvxNumberFormat(*pNewFmt); + std::unique_ptr<SvxNumberFormat> pNewFmtClone(new SvxNumberFormat(*pNewFmt)); pNewFmtClone->SetFirstLineOffset(pOldFmt->GetFirstLineOffset()); pNewFmtClone->SetAbsLSpace(pOldFmt->GetAbsLSpace()); - aNewRule.SetLevel(nLevel, pNewFmtClone); - delete pNewFmtClone; + aNewRule.SetLevel(nLevel, pNewFmtClone.get()); } } } diff --git a/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx index 02b30e958faa..29afee37a3a1 100644 --- a/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx +++ b/filter/source/xsltdialog/xmlfiltersettingsdialog.cxx @@ -1040,7 +1040,7 @@ void XMLFilterSettingsDialog::initFilterList() Sequence< PropertyValue > aValues; - filter_info_impl* pTempFilter = new filter_info_impl; + std::unique_ptr<filter_info_impl> pTempFilter( new filter_info_impl ); Sequence< OUString > aUserData; for( nFilter = 0; nFilter < nCount; nFilter++, pFilterName++ ) @@ -1187,11 +1187,11 @@ void XMLFilterSettingsDialog::initFilterList() } // add entry to internal container and to ui filter list box - maFilterVector.push_back( pTempFilter ); - m_pFilterListBox->addFilterEntry( pTempFilter ); + maFilterVector.push_back( pTempFilter.get() ); + m_pFilterListBox->addFilterEntry( pTempFilter.release() ); - pTempFilter = new filter_info_impl; + pTempFilter.reset( new filter_info_impl ); } catch( const Exception& ) { @@ -1199,8 +1199,6 @@ void XMLFilterSettingsDialog::initFilterList() } } - - delete pTempFilter; } SvTreeListEntry* pEntry = m_pFilterListBox->GetEntry( 0 ); diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index 44af35646132..f72687dd2642 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -3707,12 +3707,10 @@ void HwpReader::makeFormula(TxtBox * hbox) } mybuf[l] = '\0'; - Formula *form = new Formula(mybuf); + std::unique_ptr<Formula> form( new Formula(mybuf) ); form->setDocumentHandler(m_rxDocumentHandler); form->setAttributeListImpl(mxList.get()); form->parse(); - - delete form; } /** diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index 26f0e69663f1..7b80da245399 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -22,6 +22,7 @@ #include <string.h> #include <algorithm> #include <iostream> +#include <memory> #include <set> #include <vector> @@ -1597,11 +1598,11 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } sal_Int16 nbOfCalendars = sal::static_int_cast<sal_Int16>( getNumberOfChildren() ); OUString str; - sal_Int16 * nbOfDays = new sal_Int16[nbOfCalendars]; - sal_Int16 * nbOfMonths = new sal_Int16[nbOfCalendars]; - sal_Int16 * nbOfGenitiveMonths = new sal_Int16[nbOfCalendars]; - sal_Int16 * nbOfPartitiveMonths = new sal_Int16[nbOfCalendars]; - sal_Int16 * nbOfEras = new sal_Int16[nbOfCalendars]; + std::unique_ptr<sal_Int16[]> nbOfDays( new sal_Int16[nbOfCalendars] ); + std::unique_ptr<sal_Int16[]> nbOfMonths( new sal_Int16[nbOfCalendars] ); + std::unique_ptr<sal_Int16[]> nbOfGenitiveMonths( new sal_Int16[nbOfCalendars] ); + std::unique_ptr<sal_Int16[]> nbOfPartitiveMonths( new sal_Int16[nbOfCalendars] ); + std::unique_ptr<sal_Int16[]> nbOfEras( new sal_Int16[nbOfCalendars] ); sal_Int16 j; sal_Int16 i; bool bHasGregorian = false; @@ -1890,12 +1891,6 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const of.writeAsciiString("};\n\n"); of.writeFunction("getAllCalendars_", "calendarsCount", "calendars"); - - delete []nbOfDays; - delete []nbOfMonths; - delete []nbOfGenitiveMonths; - delete []nbOfPartitiveMonths; - delete []nbOfEras; } bool isIso4217( const OUString& rStr ) diff --git a/include/codemaker/exceptiontree.hxx b/include/codemaker/exceptiontree.hxx index 9c6b3b919b94..c291e66ce78b 100644 --- a/include/codemaker/exceptiontree.hxx +++ b/include/codemaker/exceptiontree.hxx @@ -24,6 +24,7 @@ #include <rtl/ref.hxx> #include <rtl/string.hxx> +#include <memory> #include <vector> class TypeManager; @@ -34,7 +35,7 @@ namespace codemaker { Represents a node of the hierarchy from the ExceptionTree class. */ struct ExceptionTreeNode { - typedef std::vector< ExceptionTreeNode * > Children; + typedef std::vector< std::unique_ptr<ExceptionTreeNode> > Children; // Internally used by ExceptionTree: ExceptionTreeNode(rtl::OString const & theName): diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index 1d33c929278a..41328ae421e7 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -22,6 +22,7 @@ #include <cstddef> #include <fstream> #include <iterator> +#include <memory> #include <string> #include "po.hxx" @@ -196,9 +197,9 @@ bool LngParser::Merge( OString sID( sGroup ); std::size_t nLastLangPos = 0; - ResData *pResData = new ResData( sID, sSource ); + std::unique_ptr<ResData> pResData( new ResData( sID, sSource ) ); pResData->sResTyp = "LngText"; - MergeEntrys *pEntrys = aMergeDataFile.GetMergeEntrys( pResData ); + MergeEntrys *pEntrys = aMergeDataFile.GetMergeEntrys( pResData.get() ); // read languages bGroup = false; @@ -305,8 +306,6 @@ bool LngParser::Merge( } } } - - delete pResData; } for ( size_t i = 0; i < pLines->size(); ++i ) diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 78680e844165..bb479cd2b997 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -166,10 +166,10 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil return; } - MergeDataFile* pMergeDataFile = nullptr; + std::unique_ptr<MergeDataFile> pMergeDataFile; if( m_sLang != "qtz" ) { - pMergeDataFile = new MergeDataFile( rMergeSrc, m_sSource, false, false ); + pMergeDataFile.reset( new MergeDataFile( rMergeSrc, m_sSource, false, false ) ); const std::vector<OString> vLanguages = pMergeDataFile->GetLanguages(); if( vLanguages.size()>=1 && vLanguages[0] != m_sLang ) @@ -179,7 +179,6 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil " Mergedata file: ") << m_sLang.getStr() << " - " << vLanguages[0].getStr() << std::endl; - delete pMergeDataFile; return; } } @@ -225,7 +224,6 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil } } aDestination.close(); - delete pMergeDataFile; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/lotuswordpro/source/filter/lwpgrfobj.cxx b/lotuswordpro/source/filter/lwpgrfobj.cxx index c3dc6450f7b0..ad59b6fb2b3d 100644 --- a/lotuswordpro/source/filter/lwpgrfobj.cxx +++ b/lotuswordpro/source/filter/lwpgrfobj.cxx @@ -706,13 +706,12 @@ void LwpGraphicObject::XFConvertEquation(XFContentContainer * pCont) bOk &= nEnd >= nBegin; if (bOk) { - sal_uInt8* pEquData = new sal_uInt8[nEnd - nBegin + 1]; + std::unique_ptr<sal_uInt8[]> pEquData( new sal_uInt8[nEnd - nBegin + 1] ); for(sal_uInt32 nIndex = 0; nIndex < nEnd - nBegin +1 ; nIndex++) { pEquData[nIndex] = pGrafData[nBegin + nIndex]; } - pXFNotePara->Add(OUString(reinterpret_cast<char*>(pEquData), (nEnd - nBegin + 1), osl_getThreadTextEncoding())); - delete [] pEquData; + pXFNotePara->Add(OUString(reinterpret_cast<char*>(pEquData.get()), (nEnd - nBegin + 1), osl_getThreadTextEncoding())); } pXFNote->Add(pXFNotePara); diff --git a/lotuswordpro/source/filter/lwpidxmgr.cxx b/lotuswordpro/source/filter/lwpidxmgr.cxx index 94cd789e8fd0..c38c1a16bacf 100644 --- a/lotuswordpro/source/filter/lwpidxmgr.cxx +++ b/lotuswordpro/source/filter/lwpidxmgr.cxx @@ -68,6 +68,7 @@ #include "lwpidxmgr.hxx" #include "lwptools.hxx" +#include <memory> const sal_uInt8 LwpIndexManager::MAXOBJECTIDS = 255; @@ -246,19 +247,17 @@ void LwpIndexManager::ReadObjIndex( LwpSvStream *pStrm ) LwpObjectHeader ObjHdr; ObjHdr.Read(*pStrm); - LwpObjectStream* pObjStrm = new LwpObjectStream(pStrm, ObjHdr.IsCompressed(), - static_cast<sal_uInt16>(ObjHdr.GetSize()) ); + std::unique_ptr<LwpObjectStream> pObjStrm( new LwpObjectStream(pStrm, ObjHdr.IsCompressed(), + static_cast<sal_uInt16>(ObjHdr.GetSize()) ) ); if( (sal_uInt32)VO_OBJINDEX == ObjHdr.GetTag() ) { - ReadObjIndexData( pObjStrm ); + ReadObjIndexData( pObjStrm.get() ); } else if( (sal_uInt32)VO_LEAFOBJINDEX == ObjHdr.GetTag() ) { - ReadLeafData(pObjStrm); + ReadLeafData( pObjStrm.get() ); } - - delete pObjStrm; } /** @@ -268,12 +267,10 @@ void LwpIndexManager::ReadLeafIndex( LwpSvStream *pStrm ) { LwpObjectHeader ObjHdr; ObjHdr.Read(*pStrm); - LwpObjectStream* pObjStrm = new LwpObjectStream(pStrm, ObjHdr.IsCompressed(), - static_cast<sal_uInt16>(ObjHdr.GetSize()) ); - - ReadLeafData(pObjStrm); + std::unique_ptr<LwpObjectStream> pObjStrm( new LwpObjectStream(pStrm, ObjHdr.IsCompressed(), + static_cast<sal_uInt16>(ObjHdr.GetSize()) ) ); - delete pObjStrm; + ReadLeafData(pObjStrm.get()); } /** * @descr Read data in VO_LEAFOBJINDEX diff --git a/lotuswordpro/source/filter/lwppara.cxx b/lotuswordpro/source/filter/lwppara.cxx index d5ad1969df37..82192ec7073e 100644 --- a/lotuswordpro/source/filter/lwppara.cxx +++ b/lotuswordpro/source/filter/lwppara.cxx @@ -95,6 +95,7 @@ #include "lwpdropcapmgr.hxx" #include "lwptable.hxx" +#include <memory> LwpPara::LwpPara(LwpObjectHeader& objHdr, LwpSvStream* pStrm) : LwpDLVList(objHdr, pStrm) @@ -194,10 +195,9 @@ void LwpPara::Read() { if (Notify) { - LwpForked3NotifyList* pNotifyList = new LwpForked3NotifyList(); + std::unique_ptr<LwpForked3NotifyList> pNotifyList( new LwpForked3NotifyList ); pNotifyList->GetExtraList().Read(m_pObjStrm.get()); pNotifyList->Read(m_pObjStrm.get()); - delete pNotifyList; } } } diff --git a/lotuswordpro/source/filter/lwptablelayout.cxx b/lotuswordpro/source/filter/lwptablelayout.cxx index 76f681a7a88b..c9acba7407e3 100644 --- a/lotuswordpro/source/filter/lwptablelayout.cxx +++ b/lotuswordpro/source/filter/lwptablelayout.cxx @@ -82,6 +82,7 @@ #include "xfilter/xffloatframe.hxx" #include "lwpframelayout.hxx" #include "xfilter/xfparastyle.hxx" +#include <memory> LwpSuperTableLayout::LwpSuperTableLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm) : LwpPlacableLayout(objHdr, pStrm) @@ -560,7 +561,7 @@ void LwpTableLayout::RegisterColumns() sal_uInt16 nCols = m_nCols; m_pColumns = new LwpColumnLayout *[nCols]; - sal_Bool * pWidthCalculated = new sal_Bool[nCols]; + std::unique_ptr<bool[]> pWidthCalculated( new bool[nCols] ); for(sal_uInt16 i=0;i<nCols; i++) { pWidthCalculated[i] = false; @@ -581,7 +582,6 @@ void LwpTableLayout::RegisterColumns() auto nColId = pColumnLayout->GetColumnID(); if (nColId >= nCols) { - delete [] pWidthCalculated; throw std::range_error("corrupt LwpTableLayout"); } m_pColumns[nColId] = pColumnLayout; @@ -642,7 +642,6 @@ void LwpTableLayout::RegisterColumns() } } } - delete [] pWidthCalculated; } /** * @short register all row styles diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx index 471ca7e12dfb..3f05381fe423 100644 --- a/o3tl/qa/test-sorted_vector.cxx +++ b/o3tl/qa/test-sorted_vector.cxx @@ -36,41 +36,38 @@ public: void testBasics() { o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec; - SwContent *p1 = new SwContent(1); - SwContent *p2 = new SwContent(2); + std::unique_ptr<SwContent> p1( new SwContent(1) ); + std::unique_ptr<SwContent> p2( new SwContent(2) ); SwContent *p3 = new SwContent(3); - SwContent *p4 = new SwContent(4); + std::unique_ptr<SwContent> p4( new SwContent(4) ); CPPUNIT_ASSERT( aVec.insert(p3).second ); - CPPUNIT_ASSERT( aVec.insert(p1).second ); + CPPUNIT_ASSERT( aVec.insert(p1.get()).second ); CPPUNIT_ASSERT( !aVec.insert(p3).second ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(2), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( p1, aVec[0] ); + CPPUNIT_ASSERT_EQUAL( p1.get(), aVec[0] ); CPPUNIT_ASSERT_EQUAL( p3, aVec[1] ); - CPPUNIT_ASSERT_EQUAL( p1, *aVec.begin() ); + CPPUNIT_ASSERT_EQUAL( p1.get(), *aVec.begin() ); CPPUNIT_ASSERT_EQUAL( p3, *(aVec.end()-1) ); - CPPUNIT_ASSERT_EQUAL( p1, aVec.front() ); + CPPUNIT_ASSERT_EQUAL( p1.get(), aVec.front() ); CPPUNIT_ASSERT_EQUAL( p3, aVec.back() ); - CPPUNIT_ASSERT( aVec.find(p1) != aVec.end() ); - CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(0), aVec.find(p1) - aVec.begin() ); + CPPUNIT_ASSERT( aVec.find(p1.get()) != aVec.end() ); + CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(0), aVec.find(p1.get()) - aVec.begin() ); CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() ); CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(1), aVec.find(p3) - aVec.begin() ); - CPPUNIT_ASSERT( bool(aVec.find(p2) == aVec.end()) ); - CPPUNIT_ASSERT( bool(aVec.find(p4) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p2.get()) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p4.get()) == aVec.end()) ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1.get()) ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p2) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p2.get()) ); aVec.DeleteAndDestroyAll(); - delete p1; - delete p2; - delete p4; } void testErase() @@ -79,7 +76,7 @@ public: SwContent *p1 = new SwContent(1); SwContent *p2 = new SwContent(2); SwContent *p3 = new SwContent(3); - SwContent *p4 = new SwContent(4); + std::unique_ptr<SwContent> p4( new SwContent(4) ); aVec.insert(p1); aVec.insert(p2); @@ -91,7 +88,7 @@ public: aVec.erase(1); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p4) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p4.get()) ); aVec.clear(); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.size() ); @@ -101,162 +98,147 @@ public: aVec.insert(p3); aVec.DeleteAndDestroyAll(); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.size() ); - delete p4; } void testInsertRange() { o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec1; - SwContent *p1 = new SwContent(1); - SwContent *p2 = new SwContent(2); - SwContent *p3 = new SwContent(3); + std::unique_ptr<SwContent> p1( new SwContent(1) ); + std::unique_ptr<SwContent> p2( new SwContent(2) ); + std::unique_ptr<SwContent> p3( new SwContent(3) ); - aVec1.insert(p1); - aVec1.insert(p2); - aVec1.insert(p3); + aVec1.insert(p1.get()); + aVec1.insert(p2.get()); + aVec1.insert(p3.get()); o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec2; aVec2.insert( aVec1 ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(3), aVec2.size() ); - delete p1; - delete p2; - delete p3; } void testLowerBound() { o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec; - SwContent *p1 = new SwContent(1); - SwContent *p2 = new SwContent(2); - SwContent *p3 = new SwContent(3); - SwContent *p4 = new SwContent(4); + std::unique_ptr<SwContent> p1( new SwContent(1) ); + std::unique_ptr<SwContent> p2( new SwContent(2) ); + std::unique_ptr<SwContent> p3( new SwContent(3) ); + std::unique_ptr<SwContent> p4( new SwContent(4) ); - aVec.insert(p1); - aVec.insert(p2); - aVec.insert(p3); + aVec.insert(p1.get()); + aVec.insert(p2.get()); + aVec.insert(p3.get()); - CPPUNIT_ASSERT( bool(aVec.lower_bound(p1) == aVec.begin()) ); - CPPUNIT_ASSERT( bool(aVec.lower_bound(p4) == aVec.end()) ); - delete p1; - delete p2; - delete p3; - delete p4; + CPPUNIT_ASSERT( bool(aVec.lower_bound(p1.get()) == aVec.begin()) ); + CPPUNIT_ASSERT( bool(aVec.lower_bound(p4.get()) == aVec.end()) ); } void testBasics_FindPtr() { o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, o3tl::find_partialorder_ptrequals> aVec; - SwContent *p1 = new SwContent(1); - SwContent *p2 = new SwContent(2); + std::unique_ptr<SwContent> p1( new SwContent(1) ); + std::unique_ptr<SwContent> p2( new SwContent(2) ); SwContent *p2_2 = new SwContent(2); - SwContent *p2_3 = new SwContent(2); + std::unique_ptr<SwContent> p2_3( new SwContent(2) ); SwContent *p2_4 = new SwContent(2); SwContent *p3 = new SwContent(3); - SwContent *p4 = new SwContent(4); + std::unique_ptr<SwContent> p4( new SwContent(4) ); CPPUNIT_ASSERT( aVec.insert(p3).second ); - CPPUNIT_ASSERT( aVec.insert(p1).second ); + CPPUNIT_ASSERT( aVec.insert(p1.get()).second ); CPPUNIT_ASSERT( !aVec.insert(p3).second ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(2), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( p1, aVec[0] ); + CPPUNIT_ASSERT_EQUAL( p1.get(), aVec[0] ); CPPUNIT_ASSERT_EQUAL( p3, aVec[1] ); CPPUNIT_ASSERT( aVec.insert(p2_2).second ); - CPPUNIT_ASSERT( aVec.insert(p2_3).second ); + CPPUNIT_ASSERT( aVec.insert(p2_3.get()).second ); CPPUNIT_ASSERT( !aVec.insert(p2_2).second ); CPPUNIT_ASSERT( aVec.insert(p2_4).second ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(5), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( p1, *aVec.begin() ); + CPPUNIT_ASSERT_EQUAL( p1.get(), *aVec.begin() ); CPPUNIT_ASSERT_EQUAL( p3, *(aVec.end()-1) ); - CPPUNIT_ASSERT_EQUAL( p1, aVec.front() ); + CPPUNIT_ASSERT_EQUAL( p1.get(), aVec.front() ); CPPUNIT_ASSERT_EQUAL( p3, aVec.back() ); - CPPUNIT_ASSERT( aVec.find(p1) != aVec.end() ); - CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(0), aVec.find(p1) - aVec.begin() ); + CPPUNIT_ASSERT( aVec.find(p1.get()) != aVec.end() ); + CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(0), aVec.find(p1.get()) - aVec.begin() ); CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() ); CPPUNIT_ASSERT_EQUAL( static_cast<std::ptrdiff_t>(4), aVec.find(p3) - aVec.begin() ); - CPPUNIT_ASSERT( bool(aVec.find(p2) == aVec.end()) ); - CPPUNIT_ASSERT( bool(aVec.find(p4) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p2.get()) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p4.get()) == aVec.end()) ); CPPUNIT_ASSERT( aVec.find(p2_2) != aVec.end() ); CPPUNIT_ASSERT( aVec.find(p2_2) - aVec.begin() >= 1 ); CPPUNIT_ASSERT( aVec.find(p2_2) - aVec.begin() < 4 ); - CPPUNIT_ASSERT( aVec.find(p2_3) != aVec.end() ); - CPPUNIT_ASSERT( aVec.find(p2_3) - aVec.begin() >= 1 ); - CPPUNIT_ASSERT( aVec.find(p2_3) - aVec.begin() < 4 ); + CPPUNIT_ASSERT( aVec.find(p2_3.get()) != aVec.end() ); + CPPUNIT_ASSERT( aVec.find(p2_3.get()) - aVec.begin() >= 1 ); + CPPUNIT_ASSERT( aVec.find(p2_3.get()) - aVec.begin() < 4 ); CPPUNIT_ASSERT( aVec.find(p2_4) != aVec.end() ); CPPUNIT_ASSERT( aVec.find(p2_4) - aVec.begin() >= 1 ); CPPUNIT_ASSERT( aVec.find(p2_4) - aVec.begin() < 4 ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1.get()) ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(4), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p2) ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p2_3) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p2.get()) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p2_3.get()) ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(3), aVec.size() ); aVec.DeleteAndDestroyAll(); - delete p1; - delete p2; - delete p2_3; - delete p4; } void testErase_FindPtr() { o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, o3tl::find_partialorder_ptrequals> aVec; - SwContent *p1 = new SwContent(1); + std::unique_ptr<SwContent> p1( new SwContent(1) ); SwContent *p1_2 = new SwContent(1); - SwContent *p1_3 = new SwContent(1); + std::unique_ptr<SwContent> p1_3( new SwContent(1) ); SwContent *p2 = new SwContent(2); SwContent *p3 = new SwContent(3); - SwContent *p4 = new SwContent(4); + std::unique_ptr<SwContent> p4( new SwContent(4) ); - aVec.insert(p1); + aVec.insert(p1.get()); aVec.insert(p2); aVec.insert(p3); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1.get()) ); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(2), aVec.size() ); aVec.erase(1); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p4) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p4.get()) ); aVec.clear(); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.size() ); - aVec.insert(p1); + aVec.insert(p1.get()); aVec.insert(p2); aVec.insert(p3); aVec.insert(p1_2); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(4), aVec.size() ); - aVec.insert(p1_3); + aVec.insert(p1_3.get()); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(5), aVec.size() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1) ); - CPPUNIT_ASSERT( bool(aVec.find(p1) == aVec.end()) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1.get()) ); + CPPUNIT_ASSERT( bool(aVec.find(p1.get()) == aVec.end()) ); CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); - CPPUNIT_ASSERT( aVec.find(p1_3) != aVec.end() ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1_3) ); - CPPUNIT_ASSERT( bool(aVec.find(p1) == aVec.end()) ); + CPPUNIT_ASSERT( aVec.find(p1_3.get()) != aVec.end() ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(1), aVec.erase(p1_3.get()) ); + CPPUNIT_ASSERT( bool(aVec.find(p1.get()) == aVec.end()) ); CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); - CPPUNIT_ASSERT( bool(aVec.find(p1_3) == aVec.end()) ); - CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p1_3) ); - CPPUNIT_ASSERT( bool(aVec.find(p1) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p1_3.get()) == aVec.end()) ); + CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.erase(p1_3.get()) ); + CPPUNIT_ASSERT( bool(aVec.find(p1.get()) == aVec.end()) ); CPPUNIT_ASSERT( aVec.find(p1_2) != aVec.end() ); - CPPUNIT_ASSERT( bool(aVec.find(p1_3) == aVec.end()) ); + CPPUNIT_ASSERT( bool(aVec.find(p1_3.get()) == aVec.end()) ); aVec.DeleteAndDestroyAll(); CPPUNIT_ASSERT_EQUAL( static_cast<size_t>(0), aVec.size() ); - delete p1; - delete p1_3; - delete p4; } diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx index 59e712f5a966..c2b5f338e310 100644 --- a/registry/source/reflwrit.cxx +++ b/registry/source/reflwrit.cxx @@ -892,7 +892,7 @@ void TypeWriter::createBlop() if (m_methodCount) { - sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount]; + std::unique_ptr<sal_uInt16[]> pMethodEntrySize( new sal_uInt16[m_methodCount] ); sal_uInt16 cpIndexName = 0; sal_uInt16 cpIndexReturn = 0; sal_uInt16 cpIndexDoku2 = 0; @@ -1000,8 +1000,6 @@ void TypeWriter::createBlop() cpIndexName = 0; } } - - delete[] pMethodEntrySize; } // reference blop diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx index 0655a4642c43..ba49ad9f959b 100644 --- a/registry/source/regimpl.cxx +++ b/registry/source/regimpl.cxx @@ -1484,12 +1484,11 @@ RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_ sal::static_int_cast< unsigned long >(valueSize)); fprintf(stdout, "%s Data = ", indent); - sal_Unicode* value = new sal_Unicode[size]; - readString(pBuffer, value, size); + std::unique_ptr<sal_Unicode[]> value(new sal_Unicode[size]); + readString(pBuffer, value.get(), size); - OString uStr = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + OString uStr = OUStringToOString(value.get(), RTL_TEXTENCODING_UTF8); fprintf(stdout, "L\"%s\"\n", uStr.getStr()); - delete[] value; } break; case RegValueType::BINARY: diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx index 32840a69c80c..911125a6f029 100644 --- a/sal/qa/osl/process/osl_Thread.cxx +++ b/sal/qa/osl/process/osl_Thread.cxx @@ -28,17 +28,14 @@ // include files #include <sal/types.h> - #include <rtl/string.hxx> - #include <rtl/strbuf.hxx> - #include <osl/thread.hxx> - #include <osl/mutex.hxx> #include <osl/time.h> #include <string.h> +#include <memory> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -1695,13 +1692,12 @@ public: private: void SAL_CALL run() override { - oslThreadIdentifier* pId = new oslThreadIdentifier; + std::unique_ptr<oslThreadIdentifier> pId( new oslThreadIdentifier ); *pId = getIdentifier(); - idData.setData(pId); + idData.setData(pId.get()); oslThreadIdentifier* pIdData = static_cast<oslThreadIdentifier*>(idData.getData()); //t_print("Thread %d has Data %d\n", getIdentifier(), *pIdData); m_Id = *pIdData; - delete pId; } public: diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx index 84859d1a4789..6a3e32eb6523 100644 --- a/sal/qa/rtl/oustring/rtl_OUString2.cxx +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -893,9 +893,7 @@ public: // Test interning lots of things int i; static const int nSequence = 4096; - rtl::OUString *pStrs; - - pStrs = new rtl::OUString[nSequence]; + std::unique_ptr<rtl::OUString[]> pStrs(new rtl::OUString[nSequence]); for (i = 0; i < nSequence; i++) { pStrs[i] = rtl::OUString::number( sqrt( static_cast<double>(i) ) ).intern(); @@ -906,7 +904,6 @@ public: CPPUNIT_ASSERT_EQUAL_MESSAGE("double intern failed", pStrs[i].pData, aNew.pData); } - delete [] pStrs; } CPPUNIT_TEST_SUITE(construction); diff --git a/sal/qa/rtl/process/rtl_Process.cxx b/sal/qa/rtl/process/rtl_Process.cxx index ae0eb32500ba..92ff8a5950bc 100644 --- a/sal/qa/rtl/process/rtl_Process.cxx +++ b/sal/qa/rtl/process/rtl_Process.cxx @@ -119,11 +119,11 @@ public: // "osl_joinProcess returned with failure", // osl_Process_E_None == osl_error // ); - oslProcessInfo* pInfo = new oslProcessInfo; + std::unique_ptr<oslProcessInfo> pInfo( new oslProcessInfo ); //please pay attention to initial the Size to sizeof(oslProcessInfo), or else //you will get unknown error when call osl_getProcessInfo pInfo->Size = sizeof(oslProcessInfo); - osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo ); + osl_error = osl_getProcessInfo( hProcess, osl_Process_EXITCODE, pInfo.get() ); CPPUNIT_ASSERT_EQUAL_MESSAGE ( "osl_getProcessInfo returned with failure", @@ -132,7 +132,6 @@ public: printf("the exit code is %" SAL_PRIuUINT32 ".\n", pInfo->Code ); CPPUNIT_ASSERT_EQUAL_MESSAGE("rtl_getAppCommandArg or rtl_getAppCommandArgCount error.", static_cast<oslProcessExitCode>(2), pInfo->Code); - delete pInfo; } CPPUNIT_TEST_SUITE(getAppCommandArg); diff --git a/sal/qa/rtl/random/rtl_random.cxx b/sal/qa/rtl/random/rtl_random.cxx index 14421d652560..16e880d9657d 100644 --- a/sal/qa/rtl/random/rtl_random.cxx +++ b/sal/qa/rtl/random/rtl_random.cxx @@ -98,8 +98,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_addBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -107,12 +107,10 @@ public: /* rtlRandomError */ aError = rtl_random_addBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; - } void addBytes_001() @@ -120,16 +118,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); - memset(pBuffer, 0, nBufLen); + memset(pBuffer.get(), 0, nBufLen); - rtl_random_addBytes(aPool, pBuffer, nBufLen); + rtl_random_addBytes(aPool, pBuffer.get(), nBufLen); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename @@ -221,8 +218,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); rtlRandomError aError = rtl_random_getBytes(nullptr, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); @@ -230,11 +227,10 @@ public: /* rtlRandomError */ aError = rtl_random_getBytes(aPool, nullptr, 0); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_Argument, aError); - /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError */ aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_001() @@ -242,16 +238,15 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_002() @@ -259,12 +254,12 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 4; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen << 1 ]; - memset(pBuffer, 0, nBufLen << 1); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen << 1 ] ); + memset(pBuffer.get(), 0, nBufLen << 1); CPPUNIT_ASSERT_MESSAGE("memset failed", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); - rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer, nBufLen); + rtlRandomError aError = rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong parameter", rtl_Random_E_None, aError); printf("%2x %2x %2x %2x %2x %2x %2x %2x\n", pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3], pBuffer[4], pBuffer[5], pBuffer[6], pBuffer[7]); @@ -272,7 +267,6 @@ public: CPPUNIT_ASSERT_MESSAGE("internal memory overwrite", pBuffer[4] == 0 && pBuffer[5] == 0 && pBuffer[6] == 0 && pBuffer[7] == 0); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003() @@ -280,8 +274,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 1; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -292,7 +286,7 @@ public: int nCountMax = 1000000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); /* CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); */ aStat.addValue(pBuffer[0], 1); @@ -304,7 +298,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } void getBytes_003_1() @@ -312,8 +305,8 @@ public: rtlRandomPool aPool = rtl_random_createPool(); sal_uInt32 nBufLen = 256; - sal_uInt8 *pBuffer = new sal_uInt8[ nBufLen ]; - memset(pBuffer, 0, nBufLen); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nBufLen ] ); + memset(pBuffer.get(), 0, nBufLen); Statistics aStat; @@ -324,7 +317,7 @@ public: int nCountMax = 10000; for(nCount = 0;nCount < nCountMax; ++nCount) // run 100000000 through getBytes(...) { - /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer, nBufLen); + /* rtlRandomError aError = */ rtl_random_getBytes(aPool, pBuffer.get(), nBufLen); // CPPUNIT_ASSERT_MESSAGE("wrong parameter", aError == rtl_Random_E_None); for (sal_uInt32 i=0;i<nBufLen;++i) @@ -337,7 +330,6 @@ public: CPPUNIT_ASSERT_MESSAGE("deviation should be less average", aStat.getMaxDeviation() < aStat.getAverage()); rtl_random_destroyPool(aPool); - delete [] pBuffer; } // Change the following lines only, if you add, remove or rename diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx index ad16dcfe472d..f4bd0c8c5615 100644 --- a/sc/source/core/tool/chartpos.cxx +++ b/sc/source/core/tool/chartpos.cxx @@ -358,7 +358,7 @@ void ScChartPositioner::CreatePositionMap() GlueState(); const bool bNoGlue = (eGlue == ScChartGlue::NONE); - ColumnMap* pCols = new ColumnMap; + std::unique_ptr<ColumnMap> pCols( new ColumnMap ); SCROW nNoGlueRow = 0; for ( size_t i = 0, nRanges = aRangeListRef->size(); i < nRanges; ++i ) { @@ -464,7 +464,6 @@ void ScChartPositioner::CreatePositionMap() { // Only delete tables, not the ScAddress*! delete it->second; } - delete pCols; } void ScChartPositioner::InvalidateGlue() diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx index 2ea7a8642b9b..2dbe8107fae9 100644 --- a/sc/source/core/tool/rangeutl.cxx +++ b/sc/source/core/tool/rangeutl.cxx @@ -539,20 +539,16 @@ bool ScRangeStringConverter::GetRangeListFromString( sal_Int32 nOffset = 0; while( nOffset >= 0 ) { - ScRange* pRange = new ScRange; + std::unique_ptr<ScRange> pRange( new ScRange ); if ( GetRangeFromString( *pRange, rRangeListStr, pDocument, eConv, nOffset, cSeparator, cQuote ) && (nOffset >= 0) ) { - rRangeList.push_back( pRange ); - pRange = nullptr; + rRangeList.push_back( pRange.release() ); } else if (nOffset > -1) bRet = false; - //if ownership transferred to rRangeList pRange was NULLed, otherwwise - //delete it - delete pRange; } return bRet; } diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 87018f11e8b5..dcbf6b4e4df3 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -107,8 +107,8 @@ sal_uLong ScEEImport::Read( SvStream& rStream, const OUString& rBaseURL ) void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate ) { - ScProgress* pProgress = new ScProgress( mpDoc->GetDocumentShell(), - ScGlobal::GetRscString( STR_LOAD_DOC ), mpParser->ListSize(), true ); + std::unique_ptr<ScProgress> pProgress( new ScProgress( mpDoc->GetDocumentShell(), + ScGlobal::GetRscString( STR_LOAD_DOC ), mpParser->ListSize(), true ) ); sal_uLong nProgress = 0; SCCOL nStartCol, nEndCol; @@ -439,7 +439,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu pProgress->SetState( ++nProgress ); } } - DELETEZ( pProgress ); // SetOptimalHeight has its own ProgressBar + pProgress.reset(); // SetOptimalHeight has its own ProgressBar // Adjust line height, base is 100% zoom Fraction aZoom( 1, 1 ); // Factor is printer to display ratio @@ -476,7 +476,6 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu } } } - delete pProgress; } bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, SCTAB /*nTab*/, ScEEParseEntry* pE ) diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index 28f3fd6e46c0..aa002d698359 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -1174,7 +1174,7 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq ) { OUString aCode = static_cast<const SfxStringItem*>(pItem)->GetValue(); sal_uInt16 aLen = aCode.getLength(); - OUString* sFormat = new OUString[4]; + std::unique_ptr<OUString[]> sFormat( new OUString[4] ); OUString sTmpStr = ""; sal_uInt16 nCount(0); sal_uInt16 nStrCount(0); @@ -1213,7 +1213,6 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq ) nPrecision, nLeadZeroes); pTabViewShell->SetNumFmtByStr(aCode); - delete[] sFormat; } } break; diff --git a/sccomp/source/solver/LpsolveSolver.cxx b/sccomp/source/solver/LpsolveSolver.cxx index b07691eae3a4..1e22d991c23d 100644 --- a/sccomp/source/solver/LpsolveSolver.cxx +++ b/sccomp/source/solver/LpsolveSolver.cxx @@ -221,7 +221,7 @@ void SAL_CALL LpsolveSolver::solve() throw(uno::RuntimeException, std::exception table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; const std::vector<double>& rLeftCoeff = aCellsHash[aLeftAddr]; - REAL* pValues = new REAL[nVariables+1]; + std::unique_ptr<REAL[]> pValues(new REAL[nVariables+1] ); pValues[0] = 0.0; // ignored? for (nVar=0; nVar<nVariables; nVar++) pValues[nVar+1] = rLeftCoeff[nVar+1]; @@ -250,9 +250,7 @@ void SAL_CALL LpsolveSolver::solve() throw(uno::RuntimeException, std::exception default: OSL_FAIL( "unexpected enum type" ); } - add_constraint( lp, pValues, nConstrType, fRightValue ); - - delete[] pValues; + add_constraint( lp, pValues.get(), nConstrType, fRightValue ); } } diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx index f29dbfbf56f4..dcbf0dffa839 100644 --- a/scripting/source/stringresource/stringresource.cxx +++ b/scripting/source/stringresource/stringresource.cxx @@ -1571,7 +1571,7 @@ void StringResourcePersistenceImpl::importBinary( const Sequence< ::sal_Int8 >& sal_Int32 iDefault = aIn.readInt16(); (void)iDefault; - sal_Int32* pPositions = new sal_Int32[nLocaleCount + 1]; + std::unique_ptr<sal_Int32[]> pPositions( new sal_Int32[nLocaleCount + 1] ); for( sal_Int32 i = 0; i < nLocaleCount + 1; i++ ) pPositions[i] = aIn.readInt32(); @@ -1602,8 +1602,6 @@ void StringResourcePersistenceImpl::importBinary( const Sequence< ::sal_Int8 >& if( pUseAsDefaultItem != nullptr ) setDefaultLocale( pUseAsDefaultItem->m_locale ); - - delete[] pPositions; } @@ -2166,7 +2164,7 @@ bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem* pLocale sal_Int32 nTabSize = nMaxIndex - nMinIndex + 1; // Create sorted array of pointers to the id strings - const OUString** pIdPtrs = new const OUString*[nTabSize]; + std::unique_ptr<const OUString*[]> pIdPtrs( new const OUString*[nTabSize] ); for(sal_Int32 i = 0 ; i < nTabSize ; i++ ) pIdPtrs[i] = nullptr; for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index ) @@ -2192,8 +2190,6 @@ bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem* pLocale } } } - - delete[] pIdPtrs; } bSuccess = true; diff --git a/sd/source/filter/eppt/pptexsoundcollection.cxx b/sd/source/filter/eppt/pptexsoundcollection.cxx index 2027ff3dd58c..24ee032c6ac6 100644 --- a/sd/source/filter/eppt/pptexsoundcollection.cxx +++ b/sd/source/filter/eppt/pptexsoundcollection.cxx @@ -129,16 +129,15 @@ void ExSoundEntry::Write( SvStream& rSt, sal_uInt32 nId ) const SvStream* pSourceFile = ::utl::UcbStreamHelper::CreateStream( aSoundURL, StreamMode::READ ); if ( pSourceFile ) { - sal_uInt8* pBuf = new sal_uInt8[ 0x10000 ]; // 64 kB Buffer + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ 0x10000 ] ); // 64 kB Buffer while ( nBytesLeft ) { sal_uInt32 nToDo = ( nBytesLeft > 0x10000 ) ? 0x10000 : nBytesLeft; - pSourceFile->ReadBytes(pBuf, nToDo); - rSt.WriteBytes(pBuf, nToDo); + pSourceFile->ReadBytes(pBuf.get(), nToDo); + rSt.WriteBytes(pBuf.get(), nToDo); nBytesLeft -= nToDo; } delete pSourceFile; - delete[] pBuf; } } catch( css::uno::Exception& ) diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index 755ea064ac68..73a630ffff9a 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -1947,14 +1947,14 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const aGalleryUserSound.Append( aRetval ); sal_uInt32 nSoundDataLen = aSoundDataRecHd.nRecLen; - sal_uInt8* pBuf = new sal_uInt8[ nSoundDataLen ]; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nSoundDataLen ] ); - rStCtrl.ReadBytes(pBuf, nSoundDataLen); + rStCtrl.ReadBytes(pBuf.get(), nSoundDataLen); SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aGalleryUserSound.GetMainURL( INetURLObject::NO_DECODE ), StreamMode::WRITE | StreamMode::TRUNC ); if( pOStm ) { - pOStm->WriteBytes(pBuf, nSoundDataLen); + pOStm->WriteBytes(pBuf.get(), nSoundDataLen); if( pOStm->GetError() == ERRCODE_NONE ) { @@ -1964,8 +1964,6 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const delete pOStm; } - - delete[] pBuf; } } } diff --git a/sd/source/filter/ppt/propread.cxx b/sd/source/filter/ppt/propread.cxx index 383f403322ed..630ebfc03718 100644 --- a/sd/source/filter/ppt/propread.cxx +++ b/sd/source/filter/ppt/propread.cxx @@ -105,13 +105,13 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) { try { - sal_Char* pString = new sal_Char[ nItemSize ]; + std::unique_ptr<sal_Char[]> pString( new sal_Char[ nItemSize ] ); if ( mnTextEnc == RTL_TEXTENCODING_UCS2 ) { nItemSize >>= 1; if ( nItemSize > 1 ) { - sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString); + sal_Unicode* pWString = reinterpret_cast<sal_Unicode*>(pString.get()); for (sal_uInt32 i = 0; i < nItemSize; ++i) ReadUtf16( pWString[ i ] ); rString = OUString(pWString, lcl_getMaxSafeStrLen(nItemSize)); @@ -122,17 +122,16 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) } else { - SvMemoryStream::ReadBytes(pString, nItemSize); + SvMemoryStream::ReadBytes(pString.get(), nItemSize); if ( pString[ nItemSize - 1 ] == 0 ) { if ( nItemSize > 1 ) - rString = OUString(pString, rtl_str_getLength(pString), mnTextEnc); + rString = OUString(pString.get(), rtl_str_getLength(pString.get()), mnTextEnc); else rString.clear(); bRetValue = true; } } - delete[] pString; } catch( const std::bad_alloc& ) { @@ -160,18 +159,17 @@ bool PropItem::Read( OUString& rString, sal_uInt32 nStringType, bool bAlign ) { try { - sal_Unicode* pString = new sal_Unicode[ nItemSize ]; + std::unique_ptr<sal_Unicode[]> pString( new sal_Unicode[ nItemSize ] ); for (sal_uInt32 i = 0; i < nItemSize; ++i) ReadUtf16( pString[ i ] ); if ( pString[ nItemSize - 1 ] == 0 ) { if ( (sal_uInt16)nItemSize > 1 ) - rString = OUString(pString, lcl_getMaxSafeStrLen(nItemSize)); + rString = OUString(pString.get(), lcl_getMaxSafeStrLen(nItemSize)); else rString.clear(); bRetValue = true; } - delete[] pString; } catch( const std::bad_alloc& ) { @@ -299,18 +297,16 @@ void Section::GetDictionary(Dictionary& rDict) { if ( mnTextEnc == RTL_TEXTENCODING_UCS2 ) { - sal_Unicode* pWString = new sal_Unicode[nSize]; + std::unique_ptr<sal_Unicode[]> pWString( new sal_Unicode[nSize] ); for (sal_uInt32 j = 0; j < nSize; ++j) aStream.ReadUtf16(pWString[j]); - aString = OUString(pWString, lcl_getMaxSafeStrLen(nSize)); - delete[] pWString; + aString = OUString(pWString.get(), lcl_getMaxSafeStrLen(nSize)); } else { - sal_Char* pString = new sal_Char[nSize]; - aStream.ReadBytes(pString, nSize); - aString = OUString(pString, lcl_getMaxSafeStrLen(nSize), mnTextEnc); - delete[] pString; + std::unique_ptr<sal_Char[]> pString( new sal_Char[nSize] ); + aStream.ReadBytes(pString.get(), nSize); + aString = OUString(pString.get(), lcl_getMaxSafeStrLen(nSize), mnTextEnc); } } catch( const std::bad_alloc& ) @@ -457,10 +453,9 @@ void Section::Read( SotStorageStream *pStrm ) // make sure we don't overflow the section size if( nPropSize > nSecSize - nSecOfs ) nPropSize = nSecSize - nSecOfs; - sal_uInt8* pBuf = new sal_uInt8[ nPropSize ]; - nPropSize = pStrm->ReadBytes(pBuf, nPropSize); - AddProperty( nPropId, pBuf, nPropSize ); - delete[] pBuf; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nPropSize ] ); + nPropSize = pStrm->ReadBytes(pBuf.get(), nPropSize); + AddProperty( nPropId, pBuf.get(), nPropSize ); } if ( nPropId == 1 ) { @@ -518,10 +513,9 @@ void Section::Read( SotStorageStream *pStrm ) { break; } - sal_uInt8* pBuf = new sal_uInt8[ nSize ]; - nSize = pStrm->ReadBytes(pBuf, nSize); - AddProperty( 0xffffffff, pBuf, nSize ); - delete[] pBuf; + std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ nSize ] ); + nSize = pStrm->ReadBytes(pBuf.get(), nSize); + AddProperty( 0xffffffff, pBuf.get(), nSize ); } pStrm->Seek(nCurrent); } @@ -582,7 +576,7 @@ void PropRead::Read() mpSvStream->ReadUInt16( mnByteOrder ).ReadUInt16( mnFormat ).ReadUInt16( mnVersionLo ).ReadUInt16( mnVersionHi ); if ( mnByteOrder == 0xfffe ) { - sal_uInt8* pSectCLSID = new sal_uInt8[ 16 ]; + std::unique_ptr<sal_uInt8[]> pSectCLSID( new sal_uInt8[ 16 ] ); mpSvStream->ReadBytes(mApplicationCLSID, 16); mpSvStream->ReadUInt32( nSections ); if ( nSections > 2 ) // sj: PowerPoint documents are containing max 2 sections @@ -591,16 +585,15 @@ void PropRead::Read() } else for ( sal_uInt32 i = 0; i < nSections; i++ ) { - mpSvStream->ReadBytes(pSectCLSID, 16); + mpSvStream->ReadBytes(pSectCLSID.get(), 16); mpSvStream->ReadUInt32( nSectionOfs ); nCurrent = mpSvStream->Tell(); mpSvStream->Seek( nSectionOfs ); - Section aSection( pSectCLSID ); + Section aSection( pSectCLSID.get() ); aSection.Read( mpSvStream.get() ); maSections.push_back( o3tl::make_unique<Section>( aSection ) ); mpSvStream->Seek( nCurrent ); } - delete[] pSectCLSID; } } } diff --git a/sd/source/ui/docshell/docshel2.cxx b/sd/source/ui/docshell/docshel2.cxx index ecb95ba5fe16..19697127cf4b 100644 --- a/sd/source/ui/docshell/docshel2.cxx +++ b/sd/source/ui/docshell/docshel2.cxx @@ -52,7 +52,7 @@ void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect) // THUMBNAIL: here we may can set the draft mode } - ClientView* pView = new ClientView(this, pOut); + std::unique_ptr<ClientView> pView( new ClientView(this, pOut) ); pView->SetHlplVisible(false); pView->SetGridVisible(false); @@ -116,9 +116,6 @@ void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect) pOut->SetMapMode(aOldMapMode); } } - - delete pView; - } Rectangle DrawDocShell::GetVisArea(sal_uInt16 nAspect) const diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index c844c559a642..3da40797d75e 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -1940,9 +1940,9 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& r if ( !( (mpDoc->GetSdPage((sal_Int16) nPageNumber-1, PageKind::Standard))->IsExcluded() ) || (pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportHiddenSlides()) ) { - ::sd::ClientView* pView = new ::sd::ClientView( mpDocShell, pOut ); - Rectangle aVisArea = Rectangle( Point(), mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind )->GetSize() ); - vcl::Region aRegion( aVisArea ); + std::unique_ptr<::sd::ClientView> pView( new ::sd::ClientView( mpDocShell, pOut ) ); + Rectangle aVisArea = Rectangle( Point(), mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind )->GetSize() ); + vcl::Region aRegion( aVisArea ); ::sd::ViewShell* pOldViewSh = mpDocShell->GetViewShell(); ::sd::View* pOldSdView = pOldViewSh ? pOldViewSh->GetView() : nullptr; @@ -2252,8 +2252,6 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& r pView->DrawMarkedObj(*pOut); } } - - delete pView; } } } diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx index c9a6ca8637da..41cc8a120a74 100644 --- a/starmath/source/mathmlexport.cxx +++ b/starmath/source/mathmlexport.cxx @@ -612,8 +612,8 @@ void SmXMLExport::ExportBinaryHorizontal(const SmNode *pNode, int nLevel) { TG nGroup = pNode->GetToken().nGroup; - SvXMLElementExport* pRow = new SvXMLElementExport(*this, - XML_NAMESPACE_MATH, XML_MROW, true, true); + std::unique_ptr<SvXMLElementExport> pRow( new SvXMLElementExport(*this, + XML_NAMESPACE_MATH, XML_MROW, true, true) ); // Unfold the binary tree structure as long as the nodes are SmBinHorNode // with the same nGroup. This will reduce the number of nested <mrow> @@ -639,8 +639,6 @@ void SmXMLExport::ExportBinaryHorizontal(const SmNode *pNode, int nLevel) s.push(binNode->Symbol()); s.push(binNode->LeftOperand()); } - - delete pRow; } void SmXMLExport::ExportUnaryHorizontal(const SmNode *pNode, int nLevel) @@ -708,8 +706,8 @@ void SmXMLExport::ExportBinaryDiagonal(const SmNode *pNode, int nLevel) { // widebslash // We can not use <mfrac> to a backslash, so just use <mo>\</mo> - SvXMLElementExport *pRow = new SvXMLElementExport(*this, - XML_NAMESPACE_MATH, XML_MROW, true, true); + std::unique_ptr<SvXMLElementExport> pRow( new SvXMLElementExport(*this, + XML_NAMESPACE_MATH, XML_MROW, true, true) ); ExportNodes(pNode->GetSubNode(0), nLevel); @@ -721,8 +719,6 @@ void SmXMLExport::ExportBinaryDiagonal(const SmNode *pNode, int nLevel) } ExportNodes(pNode->GetSubNode(1), nLevel); - - delete pRow; } } diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index a755443f19c2..41e81263955c 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -1946,8 +1946,8 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( REMOVE_LISTENER_METHOD, // remove method of a listener interface INVALID_METHOD // method whose class is not considered, e.g. XPropertySet }; - MethodType* pMethodTypes = new MethodType[ nSourceMethodCount ]; - sal_Int32* pLocalMethodConcepts = new sal_Int32[ nSourceMethodCount ]; + std::unique_ptr<MethodType[]> pMethodTypes( new MethodType[ nSourceMethodCount ] ); + std::unique_ptr<sal_Int32[]> pLocalMethodConcepts( new sal_Int32[ nSourceMethodCount ] ); for( i = 0 ; i < nSourceMethodCount ; i++ ) { pMethodTypes[ i ] = STANDARD_METHOD; @@ -2429,9 +2429,6 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect( // ignore them in the future if( bFoundXInterface ) bXInterfaceIsInvalid = true; - - delete[] pMethodTypes; - delete[] pLocalMethodConcepts; } // Do superclasses exist? Then continue here diff --git a/svtools/source/contnr/svtabbx.cxx b/svtools/source/contnr/svtabbx.cxx index 12c6934b1259..1de0a9f80a29 100644 --- a/svtools/source/contnr/svtabbx.cxx +++ b/svtools/source/contnr/svtabbx.cxx @@ -322,9 +322,8 @@ void SvTabListBox::SetEntryText(const OUString& rStr, SvTreeListEntry* pEntry, s } GetModel()->InvalidateEntry( pEntry ); - TabListBoxEventData* pData = new TabListBoxEventData( pEntry, nTextColumn, sOldText ); - CallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED, pData ); - delete pData; + std::unique_ptr<TabListBoxEventData> pData( new TabListBoxEventData( pEntry, nTextColumn, sOldText ) ); + CallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED, pData.get() ); } OUString SvTabListBox::GetCellText( sal_uLong nPos, sal_uInt16 nCol ) const diff --git a/sw/source/core/access/accfrmobjmap.cxx b/sw/source/core/access/accfrmobjmap.cxx index 28511ab4b3b7..43da30d7dbad 100644 --- a/sw/source/core/access/accfrmobjmap.cxx +++ b/sw/source/core/access/accfrmobjmap.cxx @@ -103,20 +103,17 @@ SwAccessibleChildMap::SwAccessibleChildMap( const SwRect& rVisArea, if ( pAccImpl && pAccImpl->HasAdditionalAccessibleChildren() ) { - std::vector< vcl::Window* >* pAdditionalChildren = - new std::vector< vcl::Window* >(); - pAccImpl->GetAdditionalAccessibleChildren( pAdditionalChildren ); + std::vector< vcl::Window* > aAdditionalChildren; + pAccImpl->GetAdditionalAccessibleChildren( &aAdditionalChildren ); sal_Int32 nCounter( 0 ); - for ( std::vector< vcl::Window* >::iterator aIter = pAdditionalChildren->begin(); - aIter != pAdditionalChildren->end(); + for ( std::vector< vcl::Window* >::iterator aIter = aAdditionalChildren.begin(); + aIter != aAdditionalChildren.end(); ++aIter ) { aLower = (*aIter); insert( ++nCounter, SwAccessibleChildMapKey::XWINDOW, aLower ); } - - delete pAdditionalChildren; } } } diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index 8148dcac195a..91a0428fe09a 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1948,15 +1948,12 @@ void SwAccessibleParagraph::_getRunAttributesImpl( SwPaM* pPaM( nullptr ); { const SwTextNode* pTextNode( GetTextNode() ); - SwPosition* pStartPos = new SwPosition( *pTextNode ); + std::unique_ptr<SwPosition> pStartPos( new SwPosition( *pTextNode ) ); pStartPos->nContent.Assign( const_cast<SwTextNode*>(pTextNode), nIndex ); - SwPosition* pEndPos = new SwPosition( *pTextNode ); + std::unique_ptr<SwPosition> pEndPos( new SwPosition( *pTextNode ) ); pEndPos->nContent.Assign( const_cast<SwTextNode*>(pTextNode), nIndex+1 ); pPaM = new SwPaM( *pStartPos, *pEndPos ); - - delete pStartPos; - delete pEndPos; } // retrieve character attributes for the created PaM <pPaM> diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index aa158ceeb1e1..f7639a2ca872 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -2591,7 +2591,7 @@ void SwCursorShell::ParkCursor( const SwNodeIndex &rIdx ) SwNode *pNode = &rIdx.GetNode(); // create a new PaM - SwPaM * pNew = new SwPaM( *GetCursor()->GetPoint() ); + std::unique_ptr<SwPaM> pNew( new SwPaM( *GetCursor()->GetPoint() ) ); if( pNode->GetStartNode() ) { if( ( pNode = pNode->StartOfSectionNode())->IsTableNode() ) @@ -2618,9 +2618,9 @@ void SwCursorShell::ParkCursor( const SwNodeIndex &rIdx ) { SwCursorShell* pSh = static_cast<SwCursorShell*>(&rTmp); if( pSh->m_pCursorStack ) - pSh->ParkPams( pNew, &pSh->m_pCursorStack ); + pSh->ParkPams( pNew.get(), &pSh->m_pCursorStack ); - pSh->ParkPams( pNew, &pSh->m_pCurrentCursor ); + pSh->ParkPams( pNew.get(), &pSh->m_pCurrentCursor ); if( pSh->m_pTableCursor ) { // set table cursor always to 0 and the current one always to @@ -2637,7 +2637,6 @@ void SwCursorShell::ParkCursor( const SwNodeIndex &rIdx ) } } } - delete pNew; } /** Copy constructor diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx index c2da0bc91261..8c37fbb0cb88 100644 --- a/sw/source/core/doc/doccomp.cxx +++ b/sw/source/core/doc/doccomp.cxx @@ -588,8 +588,8 @@ Compare::Compare( sal_uLong nDiff, CompareData& rData1, CompareData& rData2 ) MovedData *pMD1, *pMD2; // Look for the differing lines { - sal_Char* pDiscard1 = new sal_Char[ rData1.GetLineCount() ]; - sal_Char* pDiscard2 = new sal_Char[ rData2.GetLineCount() ]; + std::unique_ptr<sal_Char[]> pDiscard1( new sal_Char[ rData1.GetLineCount() ] ); + std::unique_ptr<sal_Char[]> pDiscard2( new sal_Char[ rData2.GetLineCount() ] ); sal_uLong* pCount1 = new sal_uLong[ nDiff ]; sal_uLong* pCount2 = new sal_uLong[ nDiff ]; @@ -602,20 +602,17 @@ Compare::Compare( sal_uLong nDiff, CompareData& rData1, CompareData& rData2 ) // All which occur only once now have either been inserted or deleted. // All which are also contained in the other one have been moved. - SetDiscard( rData1, pDiscard1, pCount2 ); - SetDiscard( rData2, pDiscard2, pCount1 ); + SetDiscard( rData1, pDiscard1.get(), pCount2 ); + SetDiscard( rData2, pDiscard2.get(), pCount1 ); // forget the arrays again delete [] pCount1; delete [] pCount2; - CheckDiscard( rData1.GetLineCount(), pDiscard1 ); - CheckDiscard( rData2.GetLineCount(), pDiscard2 ); + CheckDiscard( rData1.GetLineCount(), pDiscard1.get() ); + CheckDiscard( rData2.GetLineCount(), pDiscard2.get() ); - pMD1 = new MovedData( rData1, pDiscard1 ); - pMD2 = new MovedData( rData2, pDiscard2 ); - - // forget the arrays again - delete [] pDiscard1; delete [] pDiscard2; + pMD1 = new MovedData( rData1, pDiscard1.get() ); + pMD2 = new MovedData( rData2, pDiscard2.get() ); } { diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index 330c677e97d1..5bcfddc5be17 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -1321,14 +1321,14 @@ void SwFEShell::Paste( SvStream& rStrm, SwPasteSdr nAction, const Point* pPt ) StartUndo(); SvtPathOptions aPathOpt; - FmFormModel* pModel = new FmFormModel( aPathOpt.GetPalettePath(), - nullptr, GetDoc()->GetDocShell() ); + std::unique_ptr<FmFormModel> pModel( new FmFormModel( aPathOpt.GetPalettePath(), + nullptr, GetDoc()->GetDocShell() ) ); pModel->GetItemPool().FreezeIdRanges(); rStrm.Seek(0); uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( rStrm ) ); - SvxDrawingLayerImport( pModel, xInputStream ); + SvxDrawingLayerImport( pModel.get(), xInputStream ); if ( !Imp()->HasDrawView() ) Imp()->MakeDrawView(); @@ -1500,7 +1500,7 @@ void SwFEShell::Paste( SvStream& rStrm, SwPasteSdr nAction, const Point* pPt ) // #i50824# // method <lcl_RemoveOleObjsFromSdrModel> replaced by <lcl_ConvertSdrOle2ObjsToSdrGrafObjs> - lcl_ConvertSdrOle2ObjsToSdrGrafObjs( pModel ); + lcl_ConvertSdrOle2ObjsToSdrGrafObjs( pModel.get() ); pView->Paste(*pModel, aPos, nullptr, SdrInsertFlags::NONE); const size_t nCnt = pView->GetMarkedObjectList().GetMarkCount(); @@ -1534,7 +1534,6 @@ void SwFEShell::Paste( SvStream& rStrm, SwPasteSdr nAction, const Point* pPt ) } EndUndo(); EndAllAction(); - delete pModel; } bool SwFEShell::Paste(const Graphic &rGrf, const OUString& rURL) diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 7a764e73b6dc..926255ab5a6e 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -7762,12 +7762,11 @@ Graphic SwDrawFrameFormat::MakeGraphic( ImageMap* ) if ( pMod ) { SdrObject *pObj = FindSdrObject(); - SdrView *pView = new SdrView( pMod ); + std::unique_ptr<SdrView> pView( new SdrView( pMod ) ); SdrPageView *pPgView = pView->ShowSdrPage(pView->GetModel()->GetPage(0)); pView->MarkObj( pObj, pPgView ); aRet = pView->GetMarkedObjBitmapEx(); pView->HideSdrPage(); - delete pView; } return aRet; } diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx index 5618e2517662..cd46bb6fb9e9 100644 --- a/sw/source/core/text/pormulti.cxx +++ b/sw/source/core/text/pormulti.cxx @@ -341,14 +341,13 @@ void SwDoubleLinePortion::PaintBracket( SwTextPaintInfo &rInf, aBlank.Width( nChWidth ); aBlank.Height( pBracket->nHeight ); { - SwFont* pTmpFnt = new SwFont( *rInf.GetFont() ); + std::unique_ptr<SwFont> pTmpFnt( new SwFont( *rInf.GetFont() ) ); SwFontScript nAct = bOpen ? pBracket->nPreScript : pBracket->nPostScript; if( SW_SCRIPTS > nAct ) pTmpFnt->SetActual( nAct ); pTmpFnt->SetProportion( 100 ); - SwFontSave aSave( rInf, pTmpFnt ); + SwFontSave aSave( rInf, pTmpFnt.get() ); aBlank.Paint( rInf ); - delete pTmpFnt; } if( bOpen ) rInf.X( rInf.X() + PreWidth() ); diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 70be938edce2..86a3de71f03b 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -1182,8 +1182,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) // Simple kerning is handled by DrawStretchText if( rInf.GetSpace() || rInf.GetKanaComp() ) { - long *pKernArray = new long[ rInf.GetLen() ]; - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + std::unique_ptr<long[]> pKernArray( new long[ rInf.GetLen() ] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); if( bStretch ) @@ -1229,7 +1229,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) pSI && pSI->CountCompChg() && lcl_IsMonoSpaceFont( rInf.GetOut() ) ) { - pSI->Compress( pKernArray, rInf.GetIdx(), rInf.GetLen(), + pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), (sal_uInt16)m_aFont.GetFontSize().Height(), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); bSpecialJust = true; @@ -1242,7 +1242,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if (!MsLangId::isKorean(aLang)) { - SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, nullptr, + SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd ); bSpecialJust = true; @@ -1256,7 +1256,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) ) { if ( pSI && pSI->CountKashida() && - pSI->KashidaJustify( pKernArray, nullptr, rInf.GetIdx(), + pSI->KashidaJustify( pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), nSpaceAdd ) != -1 ) { bSpecialJust = true; @@ -1274,7 +1274,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { // Use rInf.GetSpace() because it has more precision than // nSpaceAdd: - SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray, nullptr, + SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray.get(), nullptr, rInf.GetIdx(), rInf.GetLen(), rInf.GetNumberOfBlanks(), rInf.GetSpace() ); @@ -1309,18 +1309,18 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) pKernArray[0] = rInf.GetWidth() + nSpaceAdd; rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), 1 ); + pKernArray.get(), rInf.GetIdx(), 1 ); } else { pKernArray[ rInf.GetLen() - 2 ] += nSpaceAdd; rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } } else rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), rInf.GetLen() ); + pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } else { @@ -1346,7 +1346,6 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) rInf.GetOut().DrawText( aTmpPos, rInf.GetText(), rInf.GetIdx() + j, i - j ); } - delete[] pKernArray; } else if( bStretch ) { @@ -1390,13 +1389,13 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) bool bBullet = rInf.GetBullet(); if( m_bSymbol ) bBullet = false; - long* pKernArray = new long[ rInf.GetLen() ]; + std::unique_ptr<long[]> pKernArray( new long[ rInf.GetLen() ] ); CreateScrFont( *rInf.GetShell(), rInf.GetOut() ); long nScrPos; // get screen array - long* pScrArray = new long[ rInf.GetLen() ]; - rInf.GetOut().GetTextArray( rInf.GetText(), pScrArray, + std::unique_ptr<long[]> pScrArray( new long[ rInf.GetLen() ] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pScrArray.get(), rInf.GetIdx(), rInf.GetLen() ); // OLE: no printer available @@ -1409,12 +1408,12 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) ) m_pPrinter->SetFont( *m_pPrtFont ); } - m_pPrinter->GetTextArray( rInf.GetText(), pKernArray, rInf.GetIdx(), + m_pPrinter->GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } else { - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), rInf.GetLen() ); } @@ -1434,10 +1433,10 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) lcl_IsMonoSpaceFont( rInf.GetOut() ) ) { Point aTmpPos( aTextOriginPos ); - pSI->Compress( pScrArray, rInf.GetIdx(), rInf.GetLen(), + pSI->Compress( pScrArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), (sal_uInt16)m_aFont.GetFontSize().Height(), lcl_IsFullstopCentered( rInf.GetOut() ), &aTmpPos ); - pSI->Compress( pKernArray, rInf.GetIdx(), rInf.GetLen(), + pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), (sal_uInt16)m_aFont.GetFontSize().Height(), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); } @@ -1449,7 +1448,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if (!MsLangId::isKorean(aLang)) { - SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray, pScrArray, + SwScriptInfo::CJKJustify( rInf.GetText(), pKernArray.get(), pScrArray.get(), rInf.GetIdx(), rInf.GetLen(), aLang, nSpaceAdd ); nSpaceAdd = 0; @@ -1462,7 +1461,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if ( SwScriptInfo::IsArabicText( rInf.GetText(), rInf.GetIdx(), rInf.GetLen() ) ) { if ( pSI && pSI->CountKashida() && - pSI->KashidaJustify( pKernArray, pScrArray, rInf.GetIdx(), + pSI->KashidaJustify( pKernArray.get(), pScrArray.get(), rInf.GetIdx(), rInf.GetLen(), nSpaceAdd ) != -1 ) nSpaceAdd = 0; else @@ -1477,8 +1476,8 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if ( LANGUAGE_THAI == aLang ) { - SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray, - pScrArray, rInf.GetIdx(), + SwScriptInfo::ThaiJustify( rInf.GetText(), pKernArray.get(), + pScrArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetNumberOfBlanks(), rInf.GetSpace() ); @@ -1568,9 +1567,9 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { #endif rInf.GetOut().DrawTextArray( aTextOriginPos, rInf.GetText(), - pKernArray, rInf.GetIdx(), 1 ); + pKernArray.get(), rInf.GetIdx(), 1 ); if( bBullet ) - rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, pKernArray, + rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, pKernArray.get(), rInf.GetIdx() ? 1 : 0, 1 ); #if defined(MACOSX) || defined(IOS) } @@ -1728,7 +1727,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { CalcLinePosData aCalcLinePosData(rInf, GetFont(), nCnt, bSwitchH2V, bSwitchL2R, - nHalfSpace, pKernArray, bBidiPor); + nHalfSpace, pKernArray.get(), bBidiPor); SwForbidden aForbidden; // draw line for smart tag data @@ -1771,7 +1770,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) sal_Int32 nTmpIdx = bBullet ? ( rInf.GetIdx() ? 1 : 0 ) : rInf.GetIdx(); - rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, pKernArray + nOffs, + rInf.GetOut().DrawTextArray( aTextOriginPos, *pStr, pKernArray.get() + nOffs, nTmpIdx + nOffs , nLen - nOffs ); if (bBullet) { @@ -1809,7 +1808,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) pKernArray [ i - 1 ] -= nAdd; } } - rInf.GetOut().DrawTextArray( aTextOriginPos, aBulletOverlay, pKernArray + nOffs, + rInf.GetOut().DrawTextArray( aTextOriginPos, aBulletOverlay, pKernArray.get() + nOffs, nTmpIdx + nOffs , nLen - nOffs ); pTmpFont->SetColor( aPreviousColor ); @@ -1823,8 +1822,6 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) #endif } } - delete[] pScrArray; - delete[] pKernArray; } } @@ -1948,8 +1945,8 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) nScrPos = pKernArray[ nLn - 1 ]; else { - long* pScrArray = new long[ rInf.GetLen() ]; - rInf.GetOut().GetTextArray( rInf.GetText(), pScrArray, + std::unique_ptr<long[]> pScrArray( new long[ rInf.GetLen() ] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pScrArray.get(), rInf.GetIdx(), rInf.GetLen() ); nScrPos = pScrArray[ 0 ]; sal_Int32 nCnt = rInf.GetText().getLength(); @@ -1986,7 +1983,6 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) nChPrev = nCh; pKernArray[i-1] = nScrPos - nScr; } - delete[] pScrArray; } delete[] pKernArray; @@ -1998,14 +1994,13 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) rInf.GetOut().SetFont( *m_pPrtFont ); if( bCompress ) { - long* pKernArray = new long[nLn]; - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + std::unique_ptr<long[]> pKernArray( new long[nLn] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), nLn ); - rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray, + rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray.get(), rInf.GetIdx(), nLn, rInf.GetKanaComp(), (sal_uInt16) m_aFont.GetFontSize().Height() ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); aTextSize.Width() = pKernArray[ nLn - 1 ]; - delete[] pKernArray; } else { @@ -2495,10 +2490,10 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) nLn = 1; else if( nLn > 2 * nTextBreak2 ) nLn = 2 * nTextBreak2; - long* pKernArray = new long[ nLn ]; - rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray, + std::unique_ptr<long[]> pKernArray( new long[ nLn ] ); + rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), rInf.GetIdx(), nLn ); - if( rInf.GetScriptInfo()->Compress( pKernArray, rInf.GetIdx(), nLn, + if( rInf.GetScriptInfo()->Compress( pKernArray.get(), rInf.GetIdx(), nLn, rInf.GetKanaComp(), (sal_uInt16)GetHeight( m_nActual ), lcl_IsFullstopCentered( rInf.GetOut() ) ) ) { @@ -2514,7 +2509,6 @@ sal_Int32 SwFont::GetTextBreak( SwDrawTextInfo& rInf, long nTextWidth ) if( rInf.GetHyphPos() ) *rInf.GetHyphPos() += nTextBreak2 - nTmpBreak; // It's not perfect } - delete[] pKernArray; } nTextBreak2 = nTextBreak2 + rInf.GetIdx(); diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 6d39a48129ea..03c86353063a 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -1134,8 +1134,8 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a } else { - SwUnoInternalPaM* pInternalPam = - new SwUnoInternalPaM( *(pFormat->GetDoc()) ); + std::unique_ptr<SwUnoInternalPaM> pInternalPam( + new SwUnoInternalPaM( *(pFormat->GetDoc()) )); uno::Reference< text::XTextRange > xRg; aValue >>= xRg; if (::sw::XTextRangeToSwPaM(*pInternalPam, xRg) ) @@ -1180,7 +1180,6 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a { throw uno::RuntimeException(); } - delete pInternalPam; } } else if (pEntry->nWID == FN_TEXT_BOX) diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 058c39ad0b89..8ddb12f94b0b 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -2635,7 +2635,7 @@ SwViewShell *SwHTMLParser::CheckActionViewShell() void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, HTMLAttrs *pPostIts ) { - SwPaM* pAttrPam = new SwPaM( *m_pPam->GetPoint() ); + std::unique_ptr<SwPaM> pAttrPam( new SwPaM( *m_pPam->GetPoint() ) ); const SwNodeIndex& rEndIdx = m_pPam->GetPoint()->nNode; const sal_Int32 nEndCnt = m_pPam->GetPoint()->nContent.GetIndex(); HTMLAttr* pAttr; @@ -2973,8 +2973,6 @@ void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, aFields.pop_front(); delete pAttr; } - - delete pAttrPam; } void SwHTMLParser::NewAttr( HTMLAttr **ppAttr, const SfxPoolItem& rItem ) diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index 54f82b2071a7..160616816a0a 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -278,10 +278,9 @@ void SwBasicEscherEx::WriteHyperlinkWithinFly( SvMemoryStream& rStrm, const SwFo sal_uInt32 const nLen = tmpStrm.remainingSize(); if(nLen >0) { - sal_uInt8* pBuffer = new sal_uInt8[ nLen ]; - tmpStrm.ReadBytes(pBuffer, nLen); - rStrm.WriteBytes(pBuffer, nLen); - delete[] pBuffer; + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[ nLen ] ); + tmpStrm.ReadBytes(pBuffer.get(), nLen); + rStrm.WriteBytes(pBuffer.get(), nLen); } } void SwBasicEscherEx::PreWriteHyperlinkWithinFly(const SwFrameFormat& rFormat,EscherPropertyContainer& rPropOpt) diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index e0071f84013c..42332e51847f 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3730,12 +3730,10 @@ void WW8Export::RestoreMacroCmds() pFib->m_lcbCmds = pStream->Tell(); pStream->Seek(0); - sal_uInt8 *pBuffer = new sal_uInt8[pFib->m_lcbCmds]; - bool bReadOk = checkRead(*pStream, pBuffer, pFib->m_lcbCmds); + std::unique_ptr<sal_uInt8[]> pBuffer( new sal_uInt8[pFib->m_lcbCmds] ); + bool bReadOk = checkRead(*pStream, pBuffer.get(), pFib->m_lcbCmds); if (bReadOk) - pTableStrm->WriteBytes(pBuffer, pFib->m_lcbCmds); - delete[] pBuffer; - + pTableStrm->WriteBytes(pBuffer.get(), pFib->m_lcbCmds); } delete pStream; diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx index 8834934c115c..51b0de6d606b 100644 --- a/sw/source/filter/ww8/wrtww8gr.cxx +++ b/sw/source/filter/ww8/wrtww8gr.cxx @@ -338,7 +338,7 @@ void WW8Export::OutputLinkedOLE( const OUString& rOleId ) xOleDst->Commit(); // Ouput the cPicLocation attribute - ww::bytes* pBuf = new ww::bytes(); + std::unique_ptr<ww::bytes> pBuf( new ww::bytes ); SwWW8Writer::InsUInt16( *pBuf, NS_sprm::LN_CPicLocation ); SwWW8Writer::InsUInt32( *pBuf, rOleId.copy( 1 ).toInt32() ); @@ -352,7 +352,6 @@ void WW8Export::OutputLinkedOLE( const OUString& rOleId ) pBuf->push_back( 1 ); m_pChpPlc->AppendFkpEntry( Strm().Tell(), pBuf->size(), pBuf->data() ); - delete pBuf; } } } diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index 659ce0b4c0cd..0b5bfdaf51e5 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -3737,10 +3737,9 @@ void WW8RStyle::ImportSprms(std::size_t nPosFc, short nLen, bool bPap) if (checkSeek(*pStStrm, nPosFc)) { - sal_uInt8 *pSprms = new sal_uInt8[nLen]; - nLen = pStStrm->ReadBytes(pSprms, nLen); - ImportSprms(pSprms, nLen, bPap); - delete[] pSprms; + std::unique_ptr<sal_uInt8[]> pSprms( new sal_uInt8[nLen] ); + nLen = pStStrm->ReadBytes(pSprms.get(), nLen); + ImportSprms(pSprms.get(), nLen, bPap); } } diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index fa1a2ac7b79c..422211a9abb3 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -5950,8 +5950,8 @@ void WW8Fib::WriteHeader(SvStream& rStrm) bool bVer8 = 8 == m_nVersion; size_t nUnencryptedHdr = bVer8 ? 0x44 : 0x24; - sal_uInt8 *pDataPtr = new sal_uInt8[ nUnencryptedHdr ]; - sal_uInt8 *pData = pDataPtr; + std::unique_ptr<sal_uInt8[]> pDataPtr( new sal_uInt8[ nUnencryptedHdr ] ); + sal_uInt8 *pData = pDataPtr.get(); memset( pData, 0, nUnencryptedHdr ); sal_uLong nPos = rStrm.Tell(); @@ -6026,8 +6026,7 @@ void WW8Fib::WriteHeader(SvStream& rStrm) // Marke: "rglw" Beginning of the array of longs Set_UInt32( pData, m_cbMac ); - rStrm.WriteBytes(pDataPtr, nUnencryptedHdr); - delete[] pDataPtr; + rStrm.WriteBytes(pDataPtr.get(), nUnencryptedHdr); } void WW8Fib::Write(SvStream& rStrm) @@ -6038,8 +6037,8 @@ void WW8Fib::Write(SvStream& rStrm) size_t nUnencryptedHdr = bVer8 ? 0x44 : 0x24; - sal_uInt8 *pDataPtr = new sal_uInt8[ m_fcMin - nUnencryptedHdr ]; - sal_uInt8 *pData = pDataPtr; + std::unique_ptr<sal_uInt8[]> pDataPtr( new sal_uInt8[ m_fcMin - nUnencryptedHdr ] ); + sal_uInt8 *pData = pDataPtr.get(); memset( pData, 0, m_fcMin - nUnencryptedHdr ); sal_uLong nPos = rStrm.Tell(); @@ -6270,8 +6269,7 @@ void WW8Fib::Write(SvStream& rStrm) Set_UInt32( pData, 0); } - rStrm.WriteBytes(pDataPtr, m_fcMin - nUnencryptedHdr); - delete[] pDataPtr; + rStrm.WriteBytes(pDataPtr.get(), m_fcMin - nUnencryptedHdr); } rtl_TextEncoding WW8Fib::GetFIBCharset(sal_uInt16 chs, sal_uInt16 nLidLocale) @@ -6842,8 +6840,8 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) sal_Int32 nFFn = rFib.m_lcbSttbfffn - 2; // allocate Font Array - sal_uInt8* pA = new sal_uInt8[nFFn]; - memset(pA, 0, nFFn); + std::unique_ptr<sal_uInt8[]> pA( new sal_uInt8[nFFn] ); + memset(pA.get(), 0, nFFn); ww::WordVersion eVersion = rFib.GetFIBVersion(); @@ -6859,9 +6857,9 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) rSt.SeekRel( 2 ); // read all font information - nFFn = rSt.ReadBytes(pA, nFFn); - sal_uInt8 * const pEnd = pA + nFFn; - const sal_uInt16 nCalcMax = calcMaxFonts(pA, nFFn); + nFFn = rSt.ReadBytes(pA.get(), nFFn); + sal_uInt8 * const pEnd = pA.get() + nFFn; + const sal_uInt16 nCalcMax = calcMaxFonts(pA.get(), nFFn); if (eVersion < ww::eWW8) nMax = nCalcMax; @@ -6880,7 +6878,7 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) if( eVersion <= ww::eWW2 ) { - sal_uInt8 const * pVer2 = pA; + sal_uInt8 const * pVer2 = pA.get(); sal_uInt16 i = 0; for(; i<nMax; ++i, ++p) { @@ -6921,7 +6919,7 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) } else if( eVersion < ww::eWW8 ) { - sal_uInt8 const * pVer6 = pA; + sal_uInt8 const * pVer6 = pA.get(); sal_uInt16 i = 0; for(; i<nMax; ++i, ++p) { @@ -7003,7 +7001,7 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) const sal_uInt8 cbMinFFNPayload = 41; sal_uInt16 nValidFonts = 0; sal_Int32 nRemainingFFn = nFFn; - sal_uInt8* pRaw = pA; + sal_uInt8* pRaw = pA.get(); for (sal_uInt16 i=0; i < nMax && nRemainingFFn; ++i, ++p) { //pRaw[0] is cbFfnM1, the alleged total length of FFN - 1 @@ -7074,7 +7072,6 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib& rFib ) nMax = std::min(nMax, nValidFonts); } } - delete[] pA; } const WW8_FFN* WW8Fonts::GetFont( sal_uInt16 nNum ) const @@ -7185,8 +7182,8 @@ WW8Dop::WW8Dop(SvStream& rSt, sal_Int16 nFib, sal_Int32 nPos, sal_uInt32 nSize) fDontUseHTMLAutoSpacing = true; //default fAcetateShowAtn = true; //default const sal_uInt32 nMaxDopSize = 0x268; - sal_uInt8* pDataPtr = new sal_uInt8[ nMaxDopSize ]; - sal_uInt8* pData = pDataPtr; + std::unique_ptr<sal_uInt8[]> pDataPtr( new sal_uInt8[ nMaxDopSize ] ); + sal_uInt8* pData = pDataPtr.get(); sal_uInt32 nRead = nMaxDopSize < nSize ? nMaxDopSize : nSize; if (nSize < 2 || !checkSeek(rSt, nPos) || nRead != rSt.ReadBytes(pData, nRead)) @@ -7394,7 +7391,6 @@ WW8Dop::WW8Dop(SvStream& rSt, sal_Int16 nFib, sal_Int32 nPos, sal_uInt32 nSize) } } } - delete[] pDataPtr; } WW8Dop::WW8Dop() diff --git a/sw/source/ui/chrdlg/chardlg.cxx b/sw/source/ui/chrdlg/chardlg.cxx index 1211e6efb5f7..660d769aa340 100644 --- a/sw/source/ui/chrdlg/chardlg.cxx +++ b/sw/source/ui/chrdlg/chardlg.cxx @@ -168,7 +168,7 @@ SwCharURLPage::SwCharURLPage(vcl::Window* pParent, const SfxItemSet& rCoreSet) ::FillCharStyleListBox(*m_pVisitedLB, pView->GetDocShell()); ::FillCharStyleListBox(*m_pNotVisitedLB, pView->GetDocShell()); - TargetList* pList = new TargetList; + std::unique_ptr<TargetList> pList( new TargetList ); const SfxFrame& rFrame = pView->GetViewFrame()->GetFrame(); rFrame.GetTargetList(*pList); if ( !pList->empty() ) @@ -180,7 +180,6 @@ SwCharURLPage::SwCharURLPage(vcl::Window* pParent, const SfxItemSet& rCoreSet) m_pTargetFrameLB->InsertEntry( pList->at( i ) ); } } - delete pList; } SwCharURLPage::~SwCharURLPage() diff --git a/sw/source/uibase/dialog/SwSpellDialogChildWindow.cxx b/sw/source/uibase/dialog/SwSpellDialogChildWindow.cxx index 69d329a686c6..cc702c708780 100644 --- a/sw/source/uibase/dialog/SwSpellDialogChildWindow.cxx +++ b/sw/source/uibase/dialog/SwSpellDialogChildWindow.cxx @@ -775,9 +775,9 @@ bool SwSpellDialogChildWindow::FindNextDrawTextError_Impl(SwWrtShell& rSh) aTmpOutliner.SetPaperSize( pTextObj->GetLogicRect().GetSize() ); aTmpOutliner.SetSpeller( xSpell ); - OutlinerView* pOutlView = new OutlinerView( &aTmpOutliner, &(rView.GetEditWin()) ); + std::unique_ptr<OutlinerView> pOutlView( new OutlinerView( &aTmpOutliner, &(rView.GetEditWin()) ) ); pOutlView->GetOutliner()->SetRefDevice( rSh.getIDocumentDeviceAccess().getPrinter( false ) ); - aTmpOutliner.InsertView( pOutlView ); + aTmpOutliner.InsertView( pOutlView.get() ); Point aPt; Size aSize(1,1); Rectangle aRect( aPt, aSize ); @@ -785,8 +785,7 @@ bool SwSpellDialogChildWindow::FindNextDrawTextError_Impl(SwWrtShell& rSh) aTmpOutliner.SetText( *pParaObj ); aTmpOutliner.ClearModifyFlag(); bHasSpellError = EE_SPELL_OK != aTmpOutliner.HasSpellErrors(); - aTmpOutliner.RemoveView( pOutlView ); - delete pOutlView; + aTmpOutliner.RemoveView( pOutlView.get() ); } if(bHasSpellError) { diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index 6a1a5a22387c..69e698b6d07a 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -600,7 +600,7 @@ Polygon::Polygon( const Rectangle& rRect, sal_uInt32 nHorzRound, sal_uInt32 nVer const Point aTR( aRect.Right() - nHorzRound, aRect.Top() + nVertRound ); const Point aBR( aRect.Right() - nHorzRound, aRect.Bottom() - nVertRound ); const Point aBL( aRect.Left() + nHorzRound, aRect.Bottom() - nVertRound ); - tools::Polygon* pEllipsePoly = new tools::Polygon( Point(), nHorzRound, nVertRound ); + std::unique_ptr<tools::Polygon> pEllipsePoly( new tools::Polygon( Point(), nHorzRound, nVertRound ) ); sal_uInt16 i, nEnd, nSize4 = pEllipsePoly->GetSize() >> 2; mpImplPolygon = new ImplPolygon( pEllipsePoly->GetSize() + 1 ); @@ -621,7 +621,6 @@ Polygon::Polygon( const Rectangle& rRect, sal_uInt32 nHorzRound, sal_uInt32 nVer ( pDstAry[ i ] = pSrcAry[ i ] ) += aBR; pDstAry[ nEnd ] = pDstAry[ 0 ]; - delete pEllipsePoly; } } } diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx index 34fb6aa5df46..873f9e9f2b0f 100644 --- a/tools/source/inet/inetmime.cxx +++ b/tools/source/inet/inetmime.cxx @@ -2742,16 +2742,15 @@ void INetMIMEOutputSink::writeSequence(const sal_Unicode * pBegin, assert(pBegin && pBegin <= pEnd && "INetMIMEOutputSink::writeSequence(): Bad sequence"); - sal_Char * pBufferBegin = new sal_Char[pEnd - pBegin]; - sal_Char * pBufferEnd = pBufferBegin; + std::unique_ptr<sal_Char[]> pBufferBegin( new sal_Char[pEnd - pBegin] ); + sal_Char * pBufferEnd = pBufferBegin.get(); while (pBegin != pEnd) { DBG_ASSERT(*pBegin < 256, "INetMIMEOutputSink::writeSequence(): Bad octet"); *pBufferEnd++ = sal_Char(*pBegin++); } - writeSequence(pBufferBegin, pBufferEnd); - delete[] pBufferBegin; + writeSequence(pBufferBegin.get(), pBufferEnd); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx index e516541148af..b60644fb439a 100644 --- a/vcl/source/gdi/bitmap4.cxx +++ b/vcl/source/gdi/bitmap4.cxx @@ -748,8 +748,8 @@ bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam ) { for( long nY = 0; nY < nHeight ; nY++ ) { - const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount(); - sal_uInt8* pIndexMap = new sal_uInt8[ nPalCount ]; + const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount(); + std::unique_ptr<sal_uInt8[]> pIndexMap( new sal_uInt8[ nPalCount ] ); for( sal_uInt16 i = 0; i < nPalCount; i++ ) pIndexMap[ i ] = pReadAcc->GetPaletteColor( i ).GetLuminance(); @@ -759,8 +759,6 @@ bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam ) aCol.SetIndex( pIndexMap[ pReadAcc->GetPixel( nY, nX ).GetIndex() ] ); pWriteAcc->SetPixel( nY, nX, aCol ); } - - delete[] pIndexMap; } } else diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index a1dfcf7e8e18..72b96fc397ff 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -923,15 +923,13 @@ bool ImpGraphic::ImplReadEmbedded( SvStream& rIStm ) if( GRAPHIC_FORMAT_50 == nId ) { // read new style header - VersionCompat* pCompat = new VersionCompat( rIStm, StreamMode::READ ); + std::unique_ptr<VersionCompat> pCompat( new VersionCompat( rIStm, StreamMode::READ ) ); rIStm.ReadInt32( nType ); sal_Int32 nLen; rIStm.ReadInt32( nLen ); ReadPair( rIStm, aSize ); ReadMapMode( rIStm, aMapMode ); - - delete pCompat; } else { @@ -1060,7 +1058,7 @@ bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) rOStm.WriteUInt32( GRAPHIC_FORMAT_50 ); // write new style header - VersionCompat* pCompat = new VersionCompat( rOStm, StreamMode::WRITE, 1 ); + std::unique_ptr<VersionCompat> pCompat( new VersionCompat( rOStm, StreamMode::WRITE, 1 ) ); rOStm.WriteInt32( (sal_Int32)meType ); @@ -1070,8 +1068,6 @@ bool ImpGraphic::ImplWriteEmbedded( SvStream& rOStm ) WritePair( rOStm, aSize ); WriteMapMode( rOStm, aMapMode ); - - delete pCompat; } else { diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx index ccc832f7a23a..314b42cd8a41 100644 --- a/vcl/source/gdi/salgdilayout.cxx +++ b/vcl/source/gdi/salgdilayout.cxx @@ -419,7 +419,7 @@ void SalGraphics::DrawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, if( (m_nLayout & SalLayoutFlags::BiDiRtl) || (pOutDev && pOutDev->IsRTLEnabled()) ) { // TODO: optimize, reduce new/delete calls - SalPoint **pPtAry2 = new SalPoint*[nPoly]; + std::unique_ptr<SalPoint*[]> pPtAry2( new SalPoint*[nPoly] ); sal_uLong i; for(i=0; i<nPoly; i++) { @@ -428,11 +428,10 @@ void SalGraphics::DrawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, mirror( nPoints, pPtAry[i], pPtAry2[i], pOutDev ); } - drawPolyPolygon( nPoly, pPoints, const_cast<PCONSTSALPOINT*>(pPtAry2) ); + drawPolyPolygon( nPoly, pPoints, const_cast<PCONSTSALPOINT*>(pPtAry2.get()) ); for(i=0; i<nPoly; i++) delete [] pPtAry2[i]; - delete [] pPtAry2; } else drawPolyPolygon( nPoly, pPoints, pPtAry ); @@ -486,7 +485,7 @@ bool SalGraphics::DrawPolyPolygonBezier( sal_uInt32 i_nPoly, const sal_uInt32* i if( (m_nLayout & SalLayoutFlags::BiDiRtl) || (i_pOutDev && i_pOutDev->IsRTLEnabled()) ) { // TODO: optimize, reduce new/delete calls - SalPoint **pPtAry2 = new SalPoint*[i_nPoly]; + std::unique_ptr<SalPoint*[]> pPtAry2( new SalPoint*[i_nPoly] ); sal_uLong i; for(i=0; i<i_nPoly; i++) { @@ -495,11 +494,10 @@ bool SalGraphics::DrawPolyPolygonBezier( sal_uInt32 i_nPoly, const sal_uInt32* i mirror( nPoints, i_pPtAry[i], pPtAry2[i], i_pOutDev ); } - bRet = drawPolyPolygonBezier( i_nPoly, i_pPoints, const_cast<PCONSTSALPOINT const *>(pPtAry2), i_pFlgAry ); + bRet = drawPolyPolygonBezier( i_nPoly, i_pPoints, const_cast<PCONSTSALPOINT const *>(pPtAry2.get()), i_pFlgAry ); for(i=0; i<i_nPoly; i++) delete [] pPtAry2[i]; - delete [] pPtAry2; } else bRet = drawPolyPolygonBezier( i_nPoly, i_pPoints, i_pPtAry, i_pFlgAry ); |