summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-16 16:12:24 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-16 20:45:33 +0200
commit203288c830041b41268f23b9aed5ad786a8e7ae6 (patch)
treed4c983405c3df00f4666979c5fc40fbae22924b8 /sc/source/core
parenta0796ca91174e317cdf280a35fb6a5dad2aef66f (diff)
fix leak in ScSubTotalParam
Change-Id: If839585931fc90b9910f6b95338d59ba48a1a78f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115676 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/subtotalparam.cxx23
-rw-r--r--sc/source/core/data/table3.cxx8
2 files changed, 12 insertions, 19 deletions
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<r.nSubTotals[i]; j++)
{
@@ -49,8 +49,6 @@ ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
else
{
nSubTotals[i] = 0;
- pSubTotals[i] = nullptr;
- pFunctions[i] = nullptr;
}
}
}
@@ -103,13 +101,13 @@ ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
nField[i] = r.nField[i];
nSubTotals[i] = r.nSubTotals[i];
- if ( pSubTotals[i] ) delete [] pSubTotals[i];
- if ( pFunctions[i] ) delete [] pFunctions[i];
+ pSubTotals[i].reset();
+ pFunctions[i].reset();
if ( r.nSubTotals[i] > 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<r.nSubTotals[i]; j++)
{
@@ -120,8 +118,6 @@ ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
else
{
nSubTotals[i] = 0;
- pSubTotals[i] = nullptr;
- pFunctions[i] = nullptr;
}
}
@@ -189,11 +185,8 @@ void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
if (nGroup != 0)
nGroup--;
- delete [] pSubTotals[nGroup];
- delete [] pFunctions[nGroup];
-
- pSubTotals[nGroup] = new SCCOL [nCount];
- pFunctions[nGroup] = new ScSubTotalFunc [nCount];
+ pSubTotals[nGroup].reset(new SCCOL[nCount]);
+ pFunctions[nGroup].reset(new ScSubTotalFunc[nCount]);
nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
for ( sal_uInt16 i=0; i<nCount; i++ )
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 552abe5b0370..e8837f6ca95a 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1998,7 +1998,7 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
// how many results per level
SCCOL nResCount = rParam.nSubTotals[aRowEntry.nGroupNo];
// result functions
- ScSubTotalFunc* pResFunc = rParam.pFunctions[aRowEntry.nGroupNo];
+ ScSubTotalFunc* pResFunc = rParam.pFunctions[aRowEntry.nGroupNo].get();
if (nResCount > 0) // otherwise only sort
{
@@ -2113,7 +2113,7 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
for (sal_uInt16 nLevel = 0; nLevel<nLevelCount; nLevel++)
{
const sal_uInt16 nGroupNo = nLevelCount - nLevel - 1;
- const ScSubTotalFunc* pResFunc = rParam.pFunctions[nGroupNo];
+ const ScSubTotalFunc* pResFunc = rParam.pFunctions[nGroupNo].get();
if (!pResFunc)
{
// No subtotal function given for this group => 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]);