From 203288c830041b41268f23b9aed5ad786a8e7ae6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 16 May 2021 16:12:24 +0200 Subject: fix leak in ScSubTotalParam Change-Id: If839585931fc90b9910f6b95338d59ba48a1a78f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115676 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/inc/subtotalparam.hxx | 5 +++-- sc/source/core/data/subtotalparam.cxx | 23 ++++++++--------------- sc/source/core/data/table3.cxx | 8 ++++---- sc/source/filter/xml/xmldrani.cxx | 8 ++++---- sc/source/ui/dbgui/tpsubt.cxx | 4 ++-- sc/source/ui/unoobj/datauno.cxx | 20 ++++++++++---------- 6 files changed, 31 insertions(+), 37 deletions(-) (limited to 'sc') diff --git a/sc/inc/subtotalparam.hxx b/sc/inc/subtotalparam.hxx index d9701c5379d4..8e36dad83987 100644 --- a/sc/inc/subtotalparam.hxx +++ b/sc/inc/subtotalparam.hxx @@ -10,6 +10,7 @@ #pragma once #include "global.hxx" +#include struct SC_DLLPUBLIC ScSubTotalParam { @@ -29,8 +30,8 @@ struct SC_DLLPUBLIC ScSubTotalParam bool bGroupActive[MAXSUBTOTAL]; ///< active groups SCCOL nField[MAXSUBTOTAL]; ///< associated field SCCOL nSubTotals[MAXSUBTOTAL]; ///< number of SubTotals - SCCOL* pSubTotals[MAXSUBTOTAL]; ///< array of columns to be calculated - ScSubTotalFunc* pFunctions[MAXSUBTOTAL]; ///< array of associated functions + std::unique_ptr pSubTotals[MAXSUBTOTAL]; ///< array of columns to be calculated + std::unique_ptr pFunctions[MAXSUBTOTAL]; ///< array of associated functions ScSubTotalParam(); ScSubTotalParam( const ScSubTotalParam& r ); diff --git a/sc/source/core/data/subtotalparam.cxx b/sc/source/core/data/subtotalparam.cxx index fc9a565f0d8e..e8f32954297c 100644 --- a/sc/source/core/data/subtotalparam.cxx +++ b/sc/source/core/data/subtotalparam.cxx @@ -37,8 +37,8 @@ ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) : if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] ) { nSubTotals[i] = r.nSubTotals[i]; - pSubTotals[i] = new SCCOL [r.nSubTotals[i]]; - pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]]; + pSubTotals[i].reset(new SCCOL [r.nSubTotals[i]]); + pFunctions[i].reset(new ScSubTotalFunc [r.nSubTotals[i]]); for (SCCOL j=0; j 0 ) { - pSubTotals[i] = new SCCOL [r.nSubTotals[i]]; - pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]]; + pSubTotals[i].reset(new SCCOL [r.nSubTotals[i]]); + pFunctions[i].reset(new ScSubTotalFunc [r.nSubTotals[i]]); for (SCCOL j=0; j(nCount); for ( sal_uInt16 i=0; i 0) // otherwise only sort { @@ -2113,7 +2113,7 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam ) for (sal_uInt16 nLevel = 0; nLevel no formula or @@ -2158,8 +2158,8 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam ) for (const auto& rRowEntry : aRowVector) { SCCOL nResCount = rParam.nSubTotals[rRowEntry.nGroupNo]; - SCCOL* nResCols = rParam.pSubTotals[rRowEntry.nGroupNo]; - ScSubTotalFunc* pResFunc = rParam.pFunctions[rRowEntry.nGroupNo]; + SCCOL* nResCols = rParam.pSubTotals[rRowEntry.nGroupNo].get(); + ScSubTotalFunc* pResFunc = rParam.pFunctions[rRowEntry.nGroupNo].get(); for ( SCCOL nResult=0; nResult < nResCount; ++nResult ) { aRef.Ref1.SetAbsCol(nResCols[nResult]); diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx index 756e874f91c7..d1701179d912 100644 --- a/sc/source/filter/xml/xmldrani.cxx +++ b/sc/source/filter/xml/xmldrani.cxx @@ -344,8 +344,8 @@ std::unique_ptr ScXMLDatabaseRangeContext::ConvertToDBData(const OUStr aParam.nSubTotals[nPos] = nCount; if (nCount != 0) { - aParam.pSubTotals[nPos] = new SCCOL[nCount]; - aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount]; + aParam.pSubTotals[nPos].reset(new SCCOL[nCount]); + aParam.pFunctions[nPos].reset(new ScSubTotalFunc[nCount]); const sheet::SubTotalColumn* pAry = rColumns.getConstArray(); for (SCCOL i = 0; i < nCount; ++i) @@ -356,8 +356,8 @@ std::unique_ptr ScXMLDatabaseRangeContext::ConvertToDBData(const OUStr } else { - aParam.pSubTotals[nPos] = nullptr; - aParam.pFunctions[nPos] = nullptr; + aParam.pSubTotals[nPos].reset(); + aParam.pFunctions[nPos].reset(); } ++nPos; } diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx index 4b8c2e1396be..9ece3597bb50 100644 --- a/sc/source/ui/dbgui/tpsubt.cxx +++ b/sc/source/ui/dbgui/tpsubt.cxx @@ -133,8 +133,8 @@ bool ScTpSubTotalGroup::DoReset( sal_uInt16 nGroupNo, { SCCOL nField = theSubTotalData.nField[nGroupIdx]; SCCOL nSubTotals = theSubTotalData.nSubTotals[nGroupIdx]; - SCCOL* pSubTotals = theSubTotalData.pSubTotals[nGroupIdx]; - ScSubTotalFunc* pFunctions = theSubTotalData.pFunctions[nGroupIdx]; + SCCOL* pSubTotals = theSubTotalData.pSubTotals[nGroupIdx].get(); + ScSubTotalFunc* pFunctions = theSubTotalData.pFunctions[nGroupIdx].get(); mxLbGroup->set_active( GetFieldSelPos( nField )+1 ); diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index 4691b7082326..d1c1f55bc1a1 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -507,8 +507,8 @@ void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns( aParam.nSubTotals[nPos] = nCount; if (nCount != 0) { - aParam.pSubTotals[nPos] = new SCCOL[nCount]; - aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount]; + aParam.pSubTotals[nPos].reset(new SCCOL[nCount]); + aParam.pFunctions[nPos].reset(new ScSubTotalFunc[nCount]); const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray(); for (SCCOL i=0; i(nGroupColumn); - delete aParam.pSubTotals[nPos]; - delete aParam.pFunctions[nPos]; + aParam.pSubTotals[nPos].reset(); + aParam.pFunctions[nPos].reset(); SCCOL nCount = static_cast(nColCount); aParam.nSubTotals[nPos] = nCount; if (nCount != 0) { - aParam.pSubTotals[nPos] = new SCCOL[nCount]; - aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount]; + aParam.pSubTotals[nPos].reset(new SCCOL[nCount]); + aParam.pFunctions[nPos].reset(new ScSubTotalFunc[nCount]); const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray(); for (SCCOL i=0; i