diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-12-12 11:40:13 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-12-13 09:07:03 +0100 |
commit | b4eac2d4d9fcfd1e08e5e51ba540d154faa6d083 (patch) | |
tree | 972d0d974803aabcc2cc0504d68a2af7f4464910 /sw/source | |
parent | cd431435f99c5edc249e8a1aa6685b87c6265604 (diff) |
ofz: fix brush leak
Change-Id: Iaab1d09be69fd3a47975ca360b78ca23954056af
Reviewed-on: https://gerrit.libreoffice.org/46290
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/filter/html/htmltab.cxx | 100 |
1 files changed, 44 insertions, 56 deletions
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 5680ca23b932..0551c886c022 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -267,7 +267,7 @@ typedef std::vector<std::unique_ptr<HTMLTableCell>> HTMLTableCells; class HTMLTableRow { - HTMLTableCells *m_pCells; ///< cells of the row + std::unique_ptr<HTMLTableCells> m_xCells; ///< cells of the row bool bIsEndOfGroup : 1; @@ -276,7 +276,7 @@ class HTMLTableRow SvxAdjust eAdjust; sal_Int16 eVertOri; - SvxBrushItem *pBGBrush; // background of cell from STYLE + std::unique_ptr<SvxBrushItem> xBGBrush; // background of cell from STYLE public: @@ -284,8 +284,6 @@ public: explicit HTMLTableRow( sal_uInt16 nCells ); // cells of the row are empty - ~HTMLTableRow(); - inline void SetHeight( sal_uInt16 nHeight ); sal_uInt16 GetHeight() const { return nHeight; } @@ -297,8 +295,8 @@ public: void SetVertOri( sal_Int16 eV) { eVertOri = eV; } sal_Int16 GetVertOri() const { return eVertOri; } - void SetBGBrush( SvxBrushItem *pBrush ) { pBGBrush = pBrush; } - const SvxBrushItem *GetBGBrush() const { return pBGBrush; } + void SetBGBrush(std::unique_ptr<SvxBrushItem>& rBrush ) { xBGBrush = std::move(rBrush); } + const std::unique_ptr<SvxBrushItem>& GetBGBrush() const { return xBGBrush; } void SetEndOfGroup() { bIsEndOfGroup = true; } bool IsEndOfGroup() const { return bIsEndOfGroup; } @@ -397,8 +395,8 @@ class HTMLTable SwTableBoxFormat *m_pBoxFormat; // frame::Frame-Format from SwTableBox SwTableLineFormat *m_pLineFormat; // frame::Frame-Format from SwTableLine SwTableLineFormat *m_pLineFrameFormatNoHeight; - SvxBrushItem *m_pBackgroundBrush; // background of the table - SvxBrushItem *m_pInheritedBackgroundBrush; // "inherited" background of the table + std::unique_ptr<SvxBrushItem> m_xBackgroundBrush; // background of the table + std::unique_ptr<SvxBrushItem> m_xInheritedBackgroundBrush; // "inherited" background of the table const SwStartNode *m_pCaptionStartNode; // Start-Node of the table-caption //lines for the border SvxBorderLine m_aTopBorderLine; @@ -503,8 +501,8 @@ class HTMLTable // is the border already set? bool BordersSet() const { return m_bBordersSet; } - const SvxBrushItem *GetBGBrush() const { return m_pBackgroundBrush; } - const SvxBrushItem *GetInhBGBrush() const { return m_pInheritedBackgroundBrush; } + const std::unique_ptr<SvxBrushItem>& GetBGBrush() const { return m_xBackgroundBrush; } + const std::unique_ptr<SvxBrushItem>& GetInhBGBrush() const { return m_xInheritedBackgroundBrush; } sal_uInt16 GetBorderWidth( const SvxBorderLine& rBLine, bool bWithDistance=false ) const; @@ -549,8 +547,7 @@ public: bool bHasValue, double nValue, bool bNoWrap ); // announce the start/end of a new row - void OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOri, - SvxBrushItem *pBGBrush ); + void OpenRow(SvxAdjust eAdjust, sal_Int16 eVertOri, std::unique_ptr<SvxBrushItem>& rBGBrush); void CloseRow( bool bEmpty ); // announce the end of a new section @@ -602,7 +599,7 @@ public: const SwTable *GetSwTable() const { return m_pSwTable; } - void SetBGBrush( const SvxBrushItem& rBrush ) { delete m_pBackgroundBrush; m_pBackgroundBrush = new SvxBrushItem( rBrush ); } + void SetBGBrush(const SvxBrushItem& rBrush) { m_xBackgroundBrush.reset(new SvxBrushItem(rBrush)); } const OUString& GetId() const { return m_aId; } const OUString& GetClass() const { return m_aClass; } @@ -753,30 +750,23 @@ std::unique_ptr<SwHTMLTableLayoutCell> HTMLTableCell::CreateLayoutInfo() } HTMLTableRow::HTMLTableRow(sal_uInt16 const nCells) - : m_pCells(new HTMLTableCells), + : m_xCells(new HTMLTableCells), bIsEndOfGroup(false), nHeight(0), nEmptyRows(0), eAdjust(SvxAdjust::End), eVertOri(text::VertOrientation::TOP), - pBGBrush(nullptr), bBottomBorder(false) { for( sal_uInt16 i=0; i<nCells; i++ ) { - m_pCells->push_back(o3tl::make_unique<HTMLTableCell>()); + m_xCells->push_back(o3tl::make_unique<HTMLTableCell>()); } - OSL_ENSURE(nCells == m_pCells->size(), + OSL_ENSURE(nCells == m_xCells->size(), "wrong Cell count in new HTML table row"); } -HTMLTableRow::~HTMLTableRow() -{ - delete m_pCells; - delete pBGBrush; -} - inline void HTMLTableRow::SetHeight( sal_uInt16 nHght ) { if( nHght > nHeight ) @@ -785,9 +775,9 @@ inline void HTMLTableRow::SetHeight( sal_uInt16 nHght ) inline HTMLTableCell *HTMLTableRow::GetCell( sal_uInt16 nCell ) const { - OSL_ENSURE( nCell < m_pCells->size(), + OSL_ENSURE( nCell < m_xCells->size(), "invalid cell index in HTML table row" ); - return (*m_pCells)[nCell].get(); + return (*m_xCells)[nCell].get(); } void HTMLTableRow::Expand( sal_uInt16 nCells, bool bOneCell ) @@ -795,34 +785,34 @@ void HTMLTableRow::Expand( sal_uInt16 nCells, bool bOneCell ) // This row will be filled with a single cell if bOneCell is set. // This will only work for rows that don't allow adding cells! - sal_uInt16 nColSpan = nCells - m_pCells->size(); - for (sal_uInt16 i = m_pCells->size(); i < nCells; ++i) + sal_uInt16 nColSpan = nCells - m_xCells->size(); + for (sal_uInt16 i = m_xCells->size(); i < nCells; ++i) { std::unique_ptr<HTMLTableCell> pCell(new HTMLTableCell); if( bOneCell ) pCell->SetColSpan( nColSpan ); - m_pCells->push_back(std::move(pCell)); + m_xCells->push_back(std::move(pCell)); nColSpan--; } - OSL_ENSURE(nCells == m_pCells->size(), + OSL_ENSURE(nCells == m_xCells->size(), "wrong Cell count in expanded HTML table row"); } void HTMLTableRow::Shrink( sal_uInt16 nCells ) { - OSL_ENSURE(nCells < m_pCells->size(), "number of cells too large"); + OSL_ENSURE(nCells < m_xCells->size(), "number of cells too large"); #if OSL_DEBUG_LEVEL > 0 - sal_uInt16 const nEnd = m_pCells->size(); + sal_uInt16 const nEnd = m_xCells->size(); #endif // The colspan of empty cells at the end has to be fixed to the new // number of cells. sal_uInt16 i=nCells; while( i ) { - HTMLTableCell *pCell = (*m_pCells)[--i].get(); + HTMLTableCell *pCell = (*m_xCells)[--i].get(); if( !pCell->GetContents() ) { #if OSL_DEBUG_LEVEL > 0 @@ -837,7 +827,7 @@ void HTMLTableRow::Shrink( sal_uInt16 nCells ) #if OSL_DEBUG_LEVEL > 0 for( i=nCells; i<nEnd; i++ ) { - HTMLTableCell *pCell = (*m_pCells)[i].get(); + HTMLTableCell *pCell = (*m_xCells)[i].get(); OSL_ENSURE( pCell->GetRowSpan() == 1, "RowSpan of to be deleted cell is wrong" ); OSL_ENSURE( pCell->GetColSpan() == nEnd - i, @@ -846,7 +836,7 @@ void HTMLTableRow::Shrink( sal_uInt16 nCells ) } #endif - m_pCells->erase( m_pCells->begin() + nCells, m_pCells->end() ); + m_xCells->erase(m_xCells->begin() + nCells, m_xCells->end()); } HTMLTableColumn::HTMLTableColumn(): @@ -916,7 +906,7 @@ void HTMLTable::InitCtor( const HTMLTableOptions *pOptions ) m_xBox1.reset(); m_pBoxFormat = nullptr; m_pLineFormat = nullptr; m_pLineFrameFormatNoHeight = nullptr; - m_pInheritedBackgroundBrush = nullptr; + m_xInheritedBackgroundBrush.reset(); m_pPrevStartNode = nullptr; m_pSwTable = nullptr; @@ -1007,9 +997,9 @@ void HTMLTable::InitCtor( const HTMLTableOptions *pOptions ) m_bColSpec = false; - m_pBackgroundBrush = m_pParser->CreateBrushItem( + m_xBackgroundBrush.reset(m_pParser->CreateBrushItem( pOptions->bBGColor ? &(pOptions->aBGColor) : nullptr, - pOptions->aBGImage, aEmptyOUStr, aEmptyOUStr, aEmptyOUStr ); + pOptions->aBGImage, aEmptyOUStr, aEmptyOUStr, aEmptyOUStr)); m_pContext = nullptr; m_xParentContents.reset(); @@ -1061,8 +1051,6 @@ HTMLTable::~HTMLTable() delete m_pRows; delete m_pColumns; - delete m_pBackgroundBrush; - delete m_pInheritedBackgroundBrush; delete m_pContext; @@ -1278,12 +1266,12 @@ void HTMLTable::FixFrameFormat( SwTableBox *pBox, // since the line is gonna be GC-ed (correctly). if( nRowSpan > 1 || (this != m_pTopTable && nRowSpan==m_nRows) ) { - pBGBrushItem = (*m_pRows)[nRow]->GetBGBrush(); + pBGBrushItem = (*m_pRows)[nRow]->GetBGBrush().get(); if( !pBGBrushItem && this != m_pTopTable ) { - pBGBrushItem = GetBGBrush(); + pBGBrushItem = GetBGBrush().get(); if( !pBGBrushItem ) - pBGBrushItem = GetInhBGBrush(); + pBGBrushItem = GetInhBGBrush().get(); } } } @@ -1551,15 +1539,15 @@ SwTableLine *HTMLTable::MakeTableLine( SwTableBox *pUpper, { // It doesn't make sense to set a color on a line, // if it's the outermost and simultaneously sole line of a table in a table - pBGBrushItem = pTopRow->GetBGBrush(); + pBGBrushItem = pTopRow->GetBGBrush().get(); if( !pBGBrushItem && this != m_pTopTable ) { // A background that's set on a table in a table is set on the rows. // It's the same for the background of the cell where that table is - pBGBrushItem = GetBGBrush(); + pBGBrushItem = GetBGBrush().get(); if( !pBGBrushItem ) - pBGBrushItem = GetInhBGBrush(); + pBGBrushItem = GetInhBGBrush().get(); } } if( nTopRow==nBottomRow-1 && (nRowHeight || pBGBrushItem) ) @@ -1799,14 +1787,14 @@ void HTMLTable::InheritBorders( const HTMLTable *pParent, { // the whole surrounding table is a table in a table and consists only of a single line // that's gonna be GC-ed (correctly). That's why the background of that line is copied. - pInhBG = (*pParent->m_pRows)[nRow]->GetBGBrush(); + pInhBG = (*pParent->m_pRows)[nRow]->GetBGBrush().get(); if( !pInhBG ) - pInhBG = pParent->GetBGBrush(); + pInhBG = pParent->GetBGBrush().get(); if( !pInhBG ) - pInhBG = pParent->GetInhBGBrush(); + pInhBG = pParent->GetInhBGBrush().get(); } if( pInhBG ) - m_pInheritedBackgroundBrush = new SvxBrushItem( *pInhBG ); + m_xInheritedBackgroundBrush.reset(new SvxBrushItem(*pInhBG)); } void HTMLTable::InheritVertBorders( const HTMLTable *pParent, @@ -2077,8 +2065,8 @@ inline void HTMLTable::CloseSection( bool bHead ) m_nHeadlineRepeat = m_nCurrentRow; } -void HTMLTable::OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOrient, - SvxBrushItem *pBGBrushItem ) +void HTMLTable::OpenRow(SvxAdjust eAdjust, sal_Int16 eVertOrient, + std::unique_ptr<SvxBrushItem>& rBGBrushItem) { sal_uInt16 nRowsReq = m_nCurrentRow+1; @@ -2095,8 +2083,8 @@ void HTMLTable::OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOrient, HTMLTableRow *const pCurRow = (*m_pRows)[m_nCurrentRow].get(); pCurRow->SetAdjust( eAdjust ); pCurRow->SetVertOri( eVertOrient ); - if( pBGBrushItem ) - (*m_pRows)[m_nCurrentRow]->SetBGBrush( pBGBrushItem ); + if (rBGBrushItem) + (*m_pRows)[m_nCurrentRow]->SetBGBrush(rBGBrushItem); // reset the column counter m_nCurrentColumn=0; @@ -4053,10 +4041,10 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions, if( !aId.isEmpty() ) InsertBookmark( aId ); - SvxBrushItem *pBrushItem = + std::unique_ptr<SvxBrushItem> xBrushItem( CreateBrushItem( bBGColor ? &aBGColor : nullptr, aBGImage, aStyle, - aId, aClass ); - pCurTable->OpenRow( eAdjust, eVertOri, pBrushItem ); + aId, aClass )); + pCurTable->OpenRow(eAdjust, eVertOri, xBrushItem); // If the first GetNextToken() doesn't succeed (pending input), must re-read from the beginning. SaveState( HtmlTokenId::NONE ); } |