summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-14 12:36:46 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-06-14 12:36:46 +0200
commit45d66415978d281330ea10ae8dcd8dc9a0bc2afc (patch)
tree466f35a593cef25cbe6d4cf8425fe5a0ad05ddbf /sw
parent4a38bd3440d0766bb92b910fa7d5ecc9344284c2 (diff)
Use vector<unique_ptr> for FlatFndBox::ppItemSets
(ppItemSets' members were apparently leaked in the past) Change-Id: I6687646cef7a6fa1e38f220944fa69ed18bdd12a
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/doc/docsort.cxx17
-rw-r--r--sw/source/core/inc/docsort.hxx6
2 files changed, 12 insertions, 11 deletions
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx
index 945104ceaabc..d71f9a079426 100644
--- a/sw/source/core/doc/docsort.cxx
+++ b/sw/source/core/doc/docsort.cxx
@@ -18,6 +18,7 @@
*/
#include <hintids.hxx>
+#include <o3tl/make_unique.hxx>
#include <rtl/math.hxx>
#include <unotools/collatorwrapper.hxx>
#include <unotools/localedatawrapper.hxx>
@@ -47,6 +48,7 @@
#include <unochart.hxx>
#include <set>
+#include <utility>
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star;
@@ -746,7 +748,6 @@ FlatFndBox::FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox) :
pDoc(pDocPtr),
rBoxRef(rBox),
pArr(nullptr),
- ppItemSets(nullptr),
nRow(0),
nCol(0)
{ // If the array is symmetric
@@ -771,7 +772,6 @@ FlatFndBox::~FlatFndBox()
{
FndBox_** ppTmp = const_cast<FndBox_**>(pArr);
delete [] ppTmp;
- delete [] ppItemSets;
}
/// All Lines of a Box need to have same number of Boxes
@@ -898,17 +898,16 @@ void FlatFndBox::FillFlat(const FndBox_& rBox, bool bLastBox)
SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_FORMULA ) ||
SfxItemState::SET == pFormat->GetItemState( RES_BOXATR_VALUE ) )
{
- SfxItemSet* pSet = new SfxItemSet( pDoc->GetAttrPool(),
+ auto pSet = o3tl::make_unique<SfxItemSet>( pDoc->GetAttrPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
pSet->Put( pFormat->GetAttrSet() );
- if( !ppItemSets )
+ if( ppItemSets.empty() )
{
size_t nCount = static_cast<size_t>(nRows) * nCols;
- ppItemSets = new SfxItemSet*[nCount];
- memset(ppItemSets, 0, sizeof(SfxItemSet*) * nCount);
+ ppItemSets.resize(nCount);
}
- *(ppItemSets + nOff ) = pSet;
+ ppItemSets[nOff] = std::move(pSet);
}
bModRow = true;
@@ -940,9 +939,9 @@ const FndBox_* FlatFndBox::GetBox(sal_uInt16 n_Col, sal_uInt16 n_Row) const
const SfxItemSet* FlatFndBox::GetItemSet(sal_uInt16 n_Col, sal_uInt16 n_Row) const
{
- OSL_ENSURE( !ppItemSets || ( n_Col < nCols && n_Row < nRows), "invalid array access");
+ OSL_ENSURE( ppItemSets.empty() || ( n_Col < nCols && n_Row < nRows), "invalid array access");
- return ppItemSets ? *(ppItemSets + (n_Row * nCols + n_Col )) : nullptr;
+ return !ppItemSets.empty() ? ppItemSets[n_Row * nCols + n_Col].get() : nullptr;
}
sal_uInt16 SwMovedBoxes::GetPos(const SwTableBox* pTableBox) const
diff --git a/sw/source/core/inc/docsort.hxx b/sw/source/core/inc/docsort.hxx
index b0ac209ce774..f8c1990ef9a3 100644
--- a/sw/source/core/inc/docsort.hxx
+++ b/sw/source/core/inc/docsort.hxx
@@ -21,6 +21,8 @@
#define INCLUDED_SW_SOURCE_CORE_INC_DOCSORT_HXX
#include <ndindex.hxx>
+
+#include <memory>
#include <vector>
class SwDoc;
@@ -139,7 +141,7 @@ private:
SwDoc* pDoc;
const FndBox_& rBoxRef;
const FndBox_** pArr;
- SfxItemSet** ppItemSets;
+ std::vector<std::unique_ptr<SfxItemSet>> ppItemSets;
sal_uInt16 nRows;
sal_uInt16 nCols;
@@ -149,7 +151,7 @@ private:
bool bSym;
};
-inline bool FlatFndBox::HasItemSets() const { return nullptr != ppItemSets; }
+inline bool FlatFndBox::HasItemSets() const { return !ppItemSets.empty(); }
#endif