sc/source/core/data/table3.cxx | 4 ++-- sc/source/core/tool/chartpos.cxx | 21 ++++++++++----------- sc/source/core/tool/formulagroup.cxx | 6 +++--- sc/source/filter/html/htmlpars.cxx | 12 +++++------- sc/source/filter/lotus/op.cxx | 25 +++++++++++-------------- sc/source/filter/qpro/qpro.cxx | 8 ++++---- sc/source/filter/starcalc/scflt.cxx | 9 +++++---- sc/source/ui/dbgui/tpsubt.cxx | 17 +++++++---------- sc/source/ui/docshell/docfunc.cxx | 7 ++++--- sc/source/ui/miscdlgs/crnrdlg.cxx | 12 +++++------- sfx2/source/control/bindings.cxx | 8 ++++---- sfx2/source/doc/objcont.cxx | 4 ++-- 12 files changed, 62 insertions(+), 71 deletions(-)
New commits: commit f516cff220895391c861adf1f4e93e280e1c3a17 Author: Takeshi Abe <t...@fixedpoint.jp> Date: Mon Mar 24 03:09:23 2014 +0900 Avoid possible resource leaks by boost::scoped_array Change-Id: I7b72c5680d5665b3f1f720f50a2d3ea6fc0c3e39 diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index f6fd9d3..7cbc9d7 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -60,6 +60,7 @@ #include "svl/sharedstringpool.hxx" #include <vector> +#include <boost/scoped_array.hpp> #include <boost/unordered_set.hpp> using namespace ::com::sun::star; @@ -1971,7 +1972,7 @@ SCSIZE ScTable::Query(ScQueryParam& rParamOrg, bool bKeepSub) bool ScTable::CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam) { bool bValid = true; - SCCOL* pFields = new SCCOL[nCol2-nCol1+1]; + boost::scoped_array<SCCOL> pFields(new SCCOL[nCol2-nCol1+1]); OUString aCellStr; SCCOL nCol = nCol1; OSL_ENSURE( rQueryParam.nTab != SCTAB_MAX, "rQueryParam.nTab no value, not bad but no good" ); @@ -2044,7 +2045,6 @@ bool ScTable::CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow rQueryParam.GetEntry(nIndex).eConnect = SC_OR; } } - delete [] pFields; return bValid; } diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx index e6d33f0..e73e7e0 100644 --- a/sc/source/core/tool/chartpos.cxx +++ b/sc/source/core/tool/chartpos.cxx @@ -20,6 +20,7 @@ #include "chartpos.hxx" #include "document.hxx" #include "rechead.hxx" +#include <boost/scoped_array.hpp> namespace { @@ -177,8 +178,8 @@ void ScChartPositioner::GlueState() const sal_uInt8 nFree = 2; const sal_uInt8 nGlue = 3; sal_uInt8* p; - sal_uInt8* pA = new sal_uInt8[ nCR ]; - memset( pA, 0, nCR * sizeof(sal_uInt8) ); + boost::scoped_array<sal_uInt8> pA(new sal_uInt8[ nCR ]); + memset( pA.get(), 0, nCR * sizeof(sal_uInt8) ); SCCOL nCol, nCol1, nCol2; SCROW nRow, nRow1, nRow2; @@ -191,7 +192,7 @@ void ScChartPositioner::GlueState() nRow2 = pR->aEnd.Row() - nStartRow; for ( nCol = nCol1; nCol <= nCol2; nCol++ ) { - p = pA + (sal_uLong)nCol * nR + nRow1; + p = pA.get() + (sal_uLong)nCol * nR + nRow1; for ( nRow = nRow1; nRow <= nRow2; nRow++, p++ ) *p = nOccu; } @@ -201,7 +202,7 @@ void ScChartPositioner::GlueState() sal_Bool bGlueCols = false; for ( nCol = 0; bGlue && nCol < nC; nCol++ ) { // iterate columns and try to mark as unused - p = pA + (sal_uLong)nCol * nR; + p = pA.get() + (sal_uLong)nCol * nR; for ( nRow = 0; bGlue && nRow < nR; nRow++, p++ ) { if ( *p == nOccu ) @@ -216,7 +217,7 @@ void ScChartPositioner::GlueState() else *p = nFree; } - if ( bGlue && *(p = (pA + ((((sal_uLong)nCol+1) * nR) - 1))) == nFree ) + if ( bGlue && *(p = (pA.get() + ((((sal_uLong)nCol+1) * nR) - 1))) == nFree ) { // mark column as totally unused *p = nGlue; bGlueCols = sal_True; // one unused column at least @@ -226,7 +227,7 @@ void ScChartPositioner::GlueState() sal_Bool bGlueRows = false; for ( nRow = 0; bGlue && nRow < nR; nRow++ ) { // iterate rows and try to mark as unused - p = pA + nRow; + p = pA.get() + nRow; for ( nCol = 0; bGlue && nCol < nC; nCol++, p+=nR ) { if ( *p == nOccu ) @@ -239,7 +240,7 @@ void ScChartPositioner::GlueState() else *p = nFree; } - if ( bGlue && *(p = (pA + ((((sal_uLong)nC-1) * nR) + nRow))) == nFree ) + if ( bGlue && *(p = (pA.get() + ((((sal_uLong)nC-1) * nR) + nRow))) == nFree ) { // mark row as totally unused *p = nGlue; bGlueRows = sal_True; // one unused row at least @@ -247,7 +248,7 @@ void ScChartPositioner::GlueState() } // If n=1: The upper left corner could be automagically pulled in for labeling - p = pA + 1; + p = pA.get() + 1; for ( sal_uLong n = 1; bGlue && n < nCR; n++, p++ ) { // An untouched field means we could neither reach it through rows nor columns, // thus we can't combine anything @@ -262,15 +263,13 @@ void ScChartPositioner::GlueState() eGlue = SC_CHARTGLUE_ROWS; else eGlue = SC_CHARTGLUE_COLS; - if ( *pA != nOccu ) + if ( pA[0] != nOccu ) bDummyUpperLeft = true; } else { eGlue = SC_CHARTGLUE_NONE; } - - delete [] pA; } void ScChartPositioner::CheckColRowHeaders() diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index fddc356..feadbc1 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -22,6 +22,7 @@ #include "rtl/bootstrap.hxx" #include <vector> +#include <boost/scoped_array.hpp> #include <boost/unordered_map.hpp> #define USE_DUMMY_INTERPRETER 0 @@ -490,11 +491,10 @@ public: // Write simple data back into the sheet if (meMode == WRITE_OUTPUT) { - double *pDoubles = new double[xGroup->mnLength]; + boost::scoped_array<double> pDoubles(new double[xGroup->mnLength]); for (sal_Int32 i = 0; i < xGroup->mnLength; i++) pDoubles[i] = 42.0 + i; - rDoc.SetFormulaResults(rTopPos, pDoubles, xGroup->mnLength); - delete [] pDoubles; + rDoc.SetFormulaResults(rTopPos, pDoubles.get(), xGroup->mnLength); } return true; } diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index 0260292..fbcfbf5 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -64,6 +64,7 @@ #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <boost/scoped_array.hpp> using ::editeng::SvxBorderLine; using namespace ::com::sun::star; @@ -713,10 +714,10 @@ void ScHTMLLayoutParser::SetWidths() // Why actually no pE? if ( nFirstTableCell < maList.size() ) { - sal_uInt16* pOffsets = new sal_uInt16[ nColsPerRow+1 ]; - memset( pOffsets, 0, (nColsPerRow+1) * sizeof(sal_uInt16) ); - sal_uInt16* pWidths = new sal_uInt16[ nColsPerRow ]; - memset( pWidths, 0, nColsPerRow * sizeof(sal_uInt16) ); + boost::scoped_array<sal_uInt16> pOffsets(new sal_uInt16[ nColsPerRow+1 ]); + memset( pOffsets.get(), 0, (nColsPerRow+1) * sizeof(sal_uInt16) ); + boost::scoped_array<sal_uInt16> pWidths(new sal_uInt16[ nColsPerRow ]); + memset( pWidths.get(), 0, nColsPerRow * sizeof(sal_uInt16) ); pOffsets[0] = nColOffsetStart; for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i ) { @@ -806,9 +807,6 @@ void ScHTMLLayoutParser::SetWidths() } } } - - delete [] pWidths; - delete [] pOffsets; } } if ( !pLocalColOffset->empty() ) diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx index 062a7b2..baa9bcf 100644 --- a/sc/source/filter/lotus/op.cxx +++ b/sc/source/filter/lotus/op.cxx @@ -52,6 +52,7 @@ #include <vector> #include <map> +#include <boost/scoped_array.hpp> extern WKTYP eTyp; // -> filter.cxx, aktueller Dateityp extern sal_Bool bEOF; // -> filter.cxx, zeigt Dateiende an @@ -126,8 +127,8 @@ void OP_Label( SvStream& r, sal_uInt16 n ) n -= (n > 5) ? 5 : n; - sal_Char* pText = new sal_Char[n + 1]; - r.Read( pText, n ); + boost::scoped_array<sal_Char> pText(new sal_Char[n + 1]); + r.Read( pText.get(), n ); pText[n] = 0; if (ValidColRow( static_cast<SCCOL>(nCol), nRow)) @@ -135,12 +136,10 @@ void OP_Label( SvStream& r, sal_uInt16 n ) nFormat &= 0x80; // Bit 7 belassen nFormat |= 0x75; // protected egal, special-text gesetzt - PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText ); + PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText.get() ); SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezStd ); } - - delete [] pText; } void OP_Formula( SvStream& r, sal_uInt16 /*n*/ ) @@ -354,13 +353,11 @@ void OP_Label123( SvStream& r, sal_uInt16 n ) r.ReadUInt16( nRow ).ReadUChar( nTab ).ReadUChar( nCol ); n -= (n > 4) ? 4 : n; - sal_Char* pText = new sal_Char[n + 1]; - r.Read( pText, n ); + boost::scoped_array<sal_Char> pText(new sal_Char[n + 1]); + r.Read( pText.get(), n ); pText[ n ] = 0; - PutFormString( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pText ); - - delete []pText; + PutFormString( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pText.get() ); } void OP_Number123( SvStream& r, sal_uInt16 /*n*/ ) @@ -426,12 +423,12 @@ void OP_Note123( SvStream& r, sal_uInt16 n) r.ReadUInt16( nRow ).ReadUChar( nTab ).ReadUChar( nCol ); n -= (n > 4) ? 4 : n; - sal_Char* pText = new sal_Char[n + 1]; - r.Read( pText, n ); + boost::scoped_array<sal_Char> pText(new sal_Char[n + 1]); + r.Read( pText.get(), n ); pText[ n ] = 0; - OUString aNoteText(pText, strlen(pText), pLotusRoot->eCharsetQ); - delete [] pText; + OUString aNoteText(pText.get(), strlen(pText.get()), pLotusRoot->eCharsetQ); + pText.reset(); ScAddress aPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab) ); ScNoteUtil::CreateNoteFromString( *pDoc, aPos, aNoteText, false, false ); diff --git a/sc/source/filter/qpro/qpro.cxx b/sc/source/filter/qpro/qpro.cxx index 2e24dff..254a8db 100644 --- a/sc/source/filter/qpro/qpro.cxx +++ b/sc/source/filter/qpro/qpro.cxx @@ -35,6 +35,7 @@ #include "formulacell.hxx" #include "biff.hxx" #include <tools/stream.hxx> +#include <boost/scoped_array.hpp> FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle ) { @@ -223,11 +224,10 @@ bool ScQProReader::nextRecord() void ScQProReader::readString( OUString &rString, sal_uInt16 nLength ) { - sal_Char* pText = new sal_Char[ nLength + 1 ]; - nLength = mpStream->Read(pText, nLength); + boost::scoped_array<sal_Char> pText(new sal_Char[ nLength + 1 ]); + nLength = mpStream->Read(pText.get(), nLength); pText[ nLength ] = 0; - rString = OUString( pText, strlen(pText), mpStream->GetStreamCharSet() ); - delete [] pText; + rString = OUString( pText.get(), strlen(pText.get()), mpStream->GetStreamCharSet() ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/starcalc/scflt.cxx b/sc/source/filter/starcalc/scflt.cxx index 91bcf02..da1043e 100644 --- a/sc/source/filter/starcalc/scflt.cxx +++ b/sc/source/filter/starcalc/scflt.cxx @@ -68,6 +68,7 @@ #include "tabprotection.hxx" #include "fprogressbar.hxx" +#include <boost/scoped_array.hpp> using namespace com::sun::star; @@ -1689,11 +1690,11 @@ void Sc10Import::LoadCol(SCCOL Col, SCTAB Tab) rStream.ReadUInt16( NoteLen ); if (NoteLen != 0) { - sal_Char* pNote = new sal_Char[NoteLen+1]; - rStream.Read(pNote, NoteLen); + boost::scoped_array<sal_Char> pNote(new sal_Char[NoteLen+1]); + rStream.Read(pNote.get(), NoteLen); pNote[NoteLen] = 0; - OUString aNoteText( SC10TOSTRING(pNote)); - delete [] pNote; + OUString aNoteText( SC10TOSTRING(pNote.get())); + pNote.reset(); ScAddress aPos( Col, static_cast<SCROW>(Row), Tab ); ScNoteUtil::CreateNoteFromString( *pDoc, aPos, aNoteText, false, false ); } diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx index a5fcd1b..85dc33b 100644 --- a/sc/source/ui/dbgui/tpsubt.cxx +++ b/sc/source/ui/dbgui/tpsubt.cxx @@ -30,7 +30,7 @@ #include "subtdlg.hxx" #include "tpsubt.hxx" - +#include <boost/scoped_array.hpp> // Subtotals group tabpage: @@ -203,8 +203,8 @@ bool ScTpSubTotalGroup::DoFillItemSet( sal_uInt16 nGroupNo, theSubTotalData = ((const ScSubTotalItem*)pItem)->GetSubTotalData(); } - ScSubTotalFunc* pFunctions = NULL; - SCCOL* pSubTotals = NULL; + boost::scoped_array<ScSubTotalFunc> pFunctions; + boost::scoped_array<SCCOL> pSubTotals; sal_uInt16 nGroup = mpLbGroup->GetSelectEntryPos(); sal_uInt16 nEntryCount = (sal_uInt16)mpLbColumns->GetEntryCount(); sal_uInt16 nCheckCount = mpLbColumns->GetCheckedEntryCount(); @@ -222,8 +222,8 @@ bool ScTpSubTotalGroup::DoFillItemSet( sal_uInt16 nGroupNo, { sal_uInt16 nFunction = 0; - pSubTotals = new SCCOL [nCheckCount]; - pFunctions = new ScSubTotalFunc [nCheckCount]; + pSubTotals.reset(new SCCOL [nCheckCount]); + pFunctions.reset(new ScSubTotalFunc [nCheckCount]); for ( sal_uInt16 i=0, nCheck=0; i<nEntryCount; i++ ) { @@ -238,17 +238,14 @@ bool ScTpSubTotalGroup::DoFillItemSet( sal_uInt16 nGroupNo, } } theSubTotalData.SetSubTotals( nGroupNo, // Gruppen-Nr. - pSubTotals, - pFunctions, + pSubTotals.get(), + pFunctions.get(), nCheckCount ); // Anzahl der Array-Elemente } rArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, &theSubTotalData ) ); - if ( pSubTotals ) delete [] pSubTotals; - if ( pFunctions ) delete [] pFunctions; - return true; } diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 182cf6c..e4b080b 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -87,6 +87,7 @@ #include <memory> #include <basic/basmgr.hxx> +#include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> #include <set> #include <vector> @@ -5131,7 +5132,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, bool bApi ) pDoc->BeginDrawUndo(); // wegen Hoehenanpassung } - ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; + boost::scoped_array<ScRangeData*> ppSortArray(new ScRangeData* [ nValidCount ]); sal_uInt16 j = 0; for (ScRangeName::iterator itr = itrLocalBeg; itr != itrLocalEnd; ++itr) { @@ -5145,7 +5146,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, bool bApi ) if (!r.HasType(RT_DATABASE) && !pLocalList->findByUpperName(itr->first)) ppSortArray[j++] = &r; } - qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), + qsort( (void*)ppSortArray.get(), nValidCount, sizeof(ScRangeData*), &ScRangeData_QsortNameCompare ); OUString aName; OUStringBuffer aContent; @@ -5165,7 +5166,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, bool bApi ) ++nOutRow; } - delete [] ppSortArray; + ppSortArray.reset(); if (bRecord) { diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx b/sc/source/ui/miscdlgs/crnrdlg.cxx index 974063a..9353840 100644 --- a/sc/source/ui/miscdlgs/crnrdlg.cxx +++ b/sc/source/ui/miscdlgs/crnrdlg.cxx @@ -27,7 +27,7 @@ #include "crnrdlg.hxx" #undef _CRNRDLG_CXX #include <vcl/msgbox.hxx> - +#include <boost/scoped_array.hpp> @@ -505,8 +505,8 @@ void ScColRowNameRangesDlg::UpdateNames() pLbRange->SetEntryData( nPos, (void*)nEntryDataDelim ); if ( (nCount = xColNameRanges->size()) > 0 ) { - ScRangePair** ppSortArray = xColNameRanges->CreateNameSortedArray( - nCount, pDoc ); + boost::scoped_array<ScRangePair*> ppSortArray(xColNameRanges->CreateNameSortedArray( + nCount, pDoc )); for ( j=0; j < nCount; j++ ) { const ScRange aRange(ppSortArray[j]->GetRange(0)); @@ -543,7 +543,6 @@ void ScColRowNameRangesDlg::UpdateNames() aRangeMap.insert( NameRangeMap::value_type(aInsStr, aRange) ); pLbRange->SetEntryData( nPos, (void*)nEntryDataCol ); } - delete [] ppSortArray; } aString = strDelim; aString += ScGlobal::GetRscString( STR_ROW ); @@ -552,8 +551,8 @@ void ScColRowNameRangesDlg::UpdateNames() pLbRange->SetEntryData( nPos, (void*)nEntryDataDelim ); if ( (nCount = xRowNameRanges->size()) > 0 ) { - ScRangePair** ppSortArray = xRowNameRanges->CreateNameSortedArray( - nCount, pDoc ); + boost::scoped_array<ScRangePair*> ppSortArray(xRowNameRanges->CreateNameSortedArray( + nCount, pDoc )); for ( j=0; j < nCount; j++ ) { const ScRange aRange(ppSortArray[j]->GetRange(0)); @@ -588,7 +587,6 @@ void ScColRowNameRangesDlg::UpdateNames() aRangeMap.insert( NameRangeMap::value_type(aInsStr, aRange) ); pLbRange->SetEntryData( nPos, (void*)nEntryDataRow ); } - delete [] ppSortArray; } pLbRange->SetUpdateMode( true ); diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index b1f3440..9954f9e 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -64,7 +64,7 @@ #include <sfx2/msgpool.hxx> #include <com/sun/star/frame/XModuleManager.hpp> - +#include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> using namespace ::com::sun::star; @@ -1451,7 +1451,7 @@ SfxItemSet* SfxBindings::CreateSet_Impl } // Create a Set from the ranges - sal_uInt16 *pRanges = new sal_uInt16[rFound.size() * 2 + 1]; + boost::scoped_array<sal_uInt16> pRanges(new sal_uInt16[rFound.size() * 2 + 1]); int j = 0; sal_uInt16 i = 0; while ( i < rFound.size() ) @@ -1464,8 +1464,8 @@ SfxItemSet* SfxBindings::CreateSet_Impl pRanges[j++] = rFound[i++]->nWhichId; } pRanges[j] = 0; // terminating NULL - SfxItemSet *pSet = new SfxItemSet(rPool, pRanges); - delete [] pRanges; + SfxItemSet *pSet = new SfxItemSet(rPool, pRanges.get()); + pRanges.reset(); DBG_PROFSTOP(SfxBindingsCreateSet); return pSet; } diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index 547b252..6d927e5 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -74,6 +74,7 @@ #include <sfx2/request.hxx> #include "openflag.hxx" #include "querytemplate.hxx" +#include <boost/scoped_array.hpp> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -331,7 +332,7 @@ void SfxObjectShell::LoadStyles SfxStyleSheetBasePool *pMyPool = GetStyleSheetPool(); DBG_ASSERT(pMyPool, "Dest-DocumentShell ohne StyleSheetPool"); pSourcePool->SetSearchMask(SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_ALL); - Styles_Impl *pFound = new Styles_Impl[pSourcePool->Count()]; + boost::scoped_array<Styles_Impl> pFound(new Styles_Impl[pSourcePool->Count()]); sal_uInt16 nFound = 0; SfxStyleSheetBase *pSource = pSourcePool->First(); @@ -359,7 +360,6 @@ void SfxObjectShell::LoadStyles if(pFound[i].pSource->HasFollowSupport()) pFound[i].pDest->SetFollow(pFound[i].pSource->GetParent()); } - delete [] pFound; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits