From fb5331971379f7d71413364e9d62f8264033ac67 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 3 Apr 2017 11:13:13 +0100 Subject: ofz: fix leak Change-Id: I93a7b2f77713db5c51734263b78ffc69c899987b --- sw/source/filter/ww8/ww8glsy.cxx | 1 + sw/source/filter/ww8/ww8graf2.cxx | 22 ++++---- sw/source/filter/ww8/ww8par.cxx | 12 ++--- sw/source/filter/ww8/ww8par.hxx | 4 +- sw/source/filter/ww8/ww8par2.cxx | 8 +-- sw/source/filter/ww8/ww8par4.cxx | 4 +- sw/source/filter/ww8/ww8par6.cxx | 105 +++++++++++++++++++------------------- 7 files changed, 76 insertions(+), 80 deletions(-) diff --git a/sw/source/filter/ww8/ww8glsy.cxx b/sw/source/filter/ww8/ww8glsy.cxx index 9f34feac6787..5ac6101ff948 100644 --- a/sw/source/filter/ww8/ww8glsy.cxx +++ b/sw/source/filter/ww8/ww8glsy.cxx @@ -32,6 +32,7 @@ #include #include "ww8glsy.hxx" #include "ww8par.hxx" +#include "ww8par2.hxx" WW8Glossary::WW8Glossary(tools::SvRef &refStrm, sal_uInt8 nVersion, SotStorage *pStg) diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx index 0c560bebe297..d0d332759d0f 100644 --- a/sw/source/filter/ww8/ww8graf2.cxx +++ b/sw/source/filter/ww8/ww8graf2.cxx @@ -356,13 +356,13 @@ SwFlyFrameFormat* SwWW8ImplReader::MakeGrafNotInContent(const WW8PicDesc& rPD, // Vertical shift through line spacing sal_Int32 nNetHeight = nHeight + rPD.nCT + rPD.nCB; - if( m_pSFlyPara->nLineSpace && m_pSFlyPara->nLineSpace > nNetHeight ) - m_pSFlyPara->nYPos = - (sal_uInt16)( m_pSFlyPara->nYPos + m_pSFlyPara->nLineSpace - nNetHeight ); + if (m_xSFlyPara->nLineSpace && m_xSFlyPara->nLineSpace > nNetHeight) + m_xSFlyPara->nYPos = + (sal_uInt16)( m_xSFlyPara->nYPos + m_xSFlyPara->nLineSpace - nNetHeight ); - WW8FlySet aFlySet(*this, m_pWFlyPara, m_pSFlyPara, true); + WW8FlySet aFlySet(*this, m_xWFlyPara.get(), m_xSFlyPara.get(), true); - SwFormatAnchor aAnchor(m_pSFlyPara->eAnchor); + SwFormatAnchor aAnchor(m_xSFlyPara->eAnchor); aAnchor.SetAnchor(m_pPaM->GetPoint()); aFlySet.Put(aAnchor); @@ -401,8 +401,8 @@ SwFrameFormat* SwWW8ImplReader::MakeGrafInContent(const WW8_PIC& rPic, // Resize the frame to the size of the picture if graphic is inside a frame // (only if auto-width) - if( m_pSFlyPara ) - m_pSFlyPara->BoxUpWidth( rPD.nWidth ); + if (m_xSFlyPara) + m_xSFlyPara->BoxUpWidth( rPD.nWidth ); return pFlyFormat; } @@ -433,7 +433,7 @@ SwFrameFormat* SwWW8ImplReader::ImportGraf1(WW8_PIC& rPic, SvStream* pSt, aGrfSet.Put( aCrop ); } - if( m_pWFlyPara && m_pWFlyPara->bGrafApo ) + if (m_xWFlyPara && m_xWFlyPara->bGrafApo) pRet = MakeGrafNotInContent(aPD,pGraph,aFileName,aGrfSet); else pRet = MakeGrafInContent(rPic,aPD,pGraph,aFileName,aGrfSet); @@ -589,11 +589,11 @@ SwFrameFormat* SwWW8ImplReader::ImportGraf(SdrTextObj* pTextObj, // A graphic of this type in this location is always // inline, and uses the pic in the same module as ww6 // graphics. - if (m_pWFlyPara && m_pWFlyPara->bGrafApo) + if (m_xWFlyPara && m_xWFlyPara->bGrafApo) { - WW8FlySet aFlySet(*this, m_pWFlyPara, m_pSFlyPara, true); + WW8FlySet aFlySet(*this, m_xWFlyPara.get(), m_xSFlyPara.get(), true); - SwFormatAnchor aAnchor(m_pSFlyPara->eAnchor); + SwFormatAnchor aAnchor(m_xSFlyPara->eAnchor); aAnchor.SetAnchor(m_pPaM->GetPoint()); aFlySet.Put(aAnchor); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index f86a2c263a2d..5fa0270e53da 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -2040,8 +2040,8 @@ WW8ReaderSave::WW8ReaderSave(SwWW8ImplReader* pRdr ,WW8_CP nStartCp) : mpOldAnchorStck(pRdr->m_pAnchorStck), mpOldRedlines(pRdr->m_pRedlineStack), mpOldPlcxMan(pRdr->m_pPlcxMan), - mpWFlyPara(pRdr->m_pWFlyPara), - mpSFlyPara(pRdr->m_pSFlyPara), + mpWFlyPara(pRdr->m_xWFlyPara.release()), + mpSFlyPara(pRdr->m_xSFlyPara.release()), mpPreviousNumPaM(pRdr->m_pPreviousNumPaM), mpPrevNumRule(pRdr->m_pPrevNumRule), mpTableDesc(pRdr->m_pTableDesc), @@ -2065,8 +2065,6 @@ WW8ReaderSave::WW8ReaderSave(SwWW8ImplReader* pRdr ,WW8_CP nStartCp) : = pRdr->m_bHasBorder = false; pRdr->m_bFirstPara = true; pRdr->m_nInTable = 0; - pRdr->m_pWFlyPara = nullptr; - pRdr->m_pSFlyPara = nullptr; pRdr->m_pPreviousNumPaM = nullptr; pRdr->m_pPrevNumRule = nullptr; pRdr->m_pTableDesc = nullptr; @@ -2097,8 +2095,8 @@ WW8ReaderSave::WW8ReaderSave(SwWW8ImplReader* pRdr ,WW8_CP nStartCp) : void WW8ReaderSave::Restore( SwWW8ImplReader* pRdr ) { - pRdr->m_pWFlyPara = mpWFlyPara; - pRdr->m_pSFlyPara = mpSFlyPara; + pRdr->m_xWFlyPara.reset(mpWFlyPara); + pRdr->m_xSFlyPara.reset(mpSFlyPara); pRdr->m_pPreviousNumPaM = mpPreviousNumPaM; pRdr->m_pPrevNumRule = mpPrevNumRule; pRdr->m_pTableDesc = mpTableDesc; @@ -4186,8 +4184,6 @@ SwWW8ImplReader::SwWW8ImplReader(sal_uInt8 nVersionPara, SotStorage* pStorage, , m_pDfltTextFormatColl(nullptr) , m_pStandardFormatColl(nullptr) , m_pHdFt(nullptr) - , m_pWFlyPara(nullptr) - , m_pSFlyPara(nullptr) , m_pTableDesc(nullptr) , m_pNumOlst(nullptr) , m_pDrawModel(nullptr) diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index 1be7bc99c999..69a90a6dcbc5 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1215,8 +1215,8 @@ private: WW8PLCF_HdFt* m_pHdFt; // pointer to Header / Footer - scanner class - WW8FlyPara* m_pWFlyPara; // WW-parameter - WW8SwFlyPara* m_pSFlyPara; // Sw parameters created from previous + std::unique_ptr m_xWFlyPara; // WW-parameter + std::unique_ptr m_xSFlyPara; // Sw parameters created from previous WW8TabDesc* m_pTableDesc; // description of table properties //Keep track of tables within tables diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index 669c98c48e64..a3888a2192f3 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -2484,22 +2484,22 @@ void WW8TabDesc::CreateSwTable() if (text::HoriOrientation::LEFT_AND_WIDTH == m_eOri) { - if (!m_pIo->m_nInTable && m_pIo->InLocalApo() && m_pIo->m_pSFlyPara->pFlyFormat && + if (!m_pIo->m_nInTable && m_pIo->InLocalApo() && m_pIo->m_xSFlyPara->pFlyFormat && GetMinLeft()) { //If we are inside a frame and we have a border, the frames //placement does not consider the tables border, which word //displays outside the frame, so adjust here. - SwFormatHoriOrient aHori(m_pIo->m_pSFlyPara->pFlyFormat->GetHoriOrient()); + SwFormatHoriOrient aHori(m_pIo->m_xSFlyPara->pFlyFormat->GetHoriOrient()); sal_Int16 eHori = aHori.GetHoriOrient(); if ((eHori == text::HoriOrientation::NONE) || (eHori == text::HoriOrientation::LEFT) || (eHori == text::HoriOrientation::LEFT_AND_WIDTH)) { //With multiple table, use last table settings. Perhaps //the maximum is what word does ? - aHori.SetPos(m_pIo->m_pSFlyPara->nXPos + GetMinLeft()); + aHori.SetPos(m_pIo->m_xSFlyPara->nXPos + GetMinLeft()); aHori.SetHoriOrient(text::HoriOrientation::NONE); - m_pIo->m_pSFlyPara->pFlyFormat->SetFormatAttr(aHori); + m_pIo->m_xSFlyPara->pFlyFormat->SetFormatAttr(aHori); } } else diff --git a/sw/source/filter/ww8/ww8par4.cxx b/sw/source/filter/ww8/ww8par4.cxx index 0761a370804b..a34427f880aa 100644 --- a/sw/source/filter/ww8/ww8par4.cxx +++ b/sw/source/filter/ww8/ww8par4.cxx @@ -277,11 +277,11 @@ SwFrameFormat* SwWW8ImplReader::ImportOle(const Graphic* pGrf, aSizeTwip.Height() ) ); pTempSet->Put( SwFormatVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME )); - if( m_pSFlyPara ) + if (m_xSFlyPara) { // Resize the frame to the picture size if there is an OLE object // in the frame (only if auto-width) - m_pSFlyPara->BoxUpWidth( aSizeTwip.Width() ); + m_xSFlyPara->BoxUpWidth(aSizeTwip.Width()); } } diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index b763a4627143..276a5260a337 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -2309,16 +2309,17 @@ bool SwWW8ImplReader::IsDropCap() bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *pTabPos) { - if (nullptr == (m_pWFlyPara = ConstructApo(rApo, pTabPos))) + m_xWFlyPara.reset(ConstructApo(rApo, pTabPos)); + if (!m_xWFlyPara) return false; // constructor has changed - new 4th parameter // containing WW8 page top margin. - m_pSFlyPara = new WW8SwFlyPara( *m_pPaM, *this, *m_pWFlyPara, + m_xSFlyPara.reset(new WW8SwFlyPara( *m_pPaM, *this, *m_xWFlyPara, m_aSectionManager.GetWWPageTopMargin(), m_aSectionManager.GetPageLeft(), m_aSectionManager.GetTextAreaWidth(), - m_nIniFlyDx, m_nIniFlyDy); + m_nIniFlyDx, m_nIniFlyDy)); // If this paragraph is a Dropcap set the flag and we will deal with it later if (IsDropCap()) @@ -2328,7 +2329,7 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p return false; } - if( !m_pWFlyPara->bGrafApo ) + if (!m_xWFlyPara->bGrafApo) { // Within the GrafApo text attributes have to be ignored, because @@ -2337,45 +2338,45 @@ bool SwWW8ImplReader::StartApo(const ApoTestResults &rApo, const WW8_TablePos *p // frame, pWFlyPara and pSFlyPara are retained and the resulting // attributes applied to the image when inserting the image. - WW8FlySet aFlySet(*this, m_pWFlyPara, m_pSFlyPara, false); + WW8FlySet aFlySet(*this, m_xWFlyPara.get(), m_xSFlyPara.get(), false); if (pTabPos && pTabPos->bNoFly) { - m_pSFlyPara->pFlyFormat = nullptr; + m_xSFlyPara->pFlyFormat = nullptr; } else { - m_pSFlyPara->pFlyFormat = m_rDoc.MakeFlySection( m_pSFlyPara->eAnchor, - m_pPaM->GetPoint(), &aFlySet ); - OSL_ENSURE(m_pSFlyPara->pFlyFormat->GetAnchor().GetAnchorId() == - m_pSFlyPara->eAnchor, "Not the anchor type requested!"); + m_xSFlyPara->pFlyFormat = m_rDoc.MakeFlySection(m_xSFlyPara->eAnchor, + m_pPaM->GetPoint(), &aFlySet); + OSL_ENSURE(m_xSFlyPara->pFlyFormat->GetAnchor().GetAnchorId() == + m_xSFlyPara->eAnchor, "Not the anchor type requested!"); } - if (m_pSFlyPara->pFlyFormat) + if (m_xSFlyPara->pFlyFormat) { if (!m_pDrawModel) GrafikCtor(); - SdrObject* pOurNewObject = CreateContactObject(m_pSFlyPara->pFlyFormat); + SdrObject* pOurNewObject = CreateContactObject(m_xSFlyPara->pFlyFormat); m_pWWZOrder->InsertTextLayerObject(pOurNewObject); } - if (RndStdIds::FLY_AS_CHAR != m_pSFlyPara->eAnchor && m_pSFlyPara->pFlyFormat) + if (RndStdIds::FLY_AS_CHAR != m_xSFlyPara->eAnchor && m_xSFlyPara->pFlyFormat) { - m_pAnchorStck->AddAnchor(*m_pPaM->GetPoint(),m_pSFlyPara->pFlyFormat); + m_pAnchorStck->AddAnchor(*m_pPaM->GetPoint(), m_xSFlyPara->pFlyFormat); } // remember Pos in body text - m_pSFlyPara->pMainTextPos = new SwPosition( *m_pPaM->GetPoint() ); + m_xSFlyPara->pMainTextPos = new SwPosition( *m_pPaM->GetPoint() ); //remove fltanchors, otherwise they will be closed inside the //frame, which makes no sense, restore them after the frame is //closed - m_pSFlyPara->pOldAnchorStck = m_pAnchorStck; + m_xSFlyPara->pOldAnchorStck = m_pAnchorStck; m_pAnchorStck = new SwWW8FltAnchorStack(&m_rDoc, m_nFieldFlags); - if (m_pSFlyPara->pFlyFormat) - MoveInsideFly(m_pSFlyPara->pFlyFormat); + if (m_xSFlyPara->pFlyFormat) + MoveInsideFly(m_xSFlyPara->pFlyFormat); // 1) ReadText() is not called recursively because the length of // the Apo is unknown at that time, and ReadText() needs it. @@ -2444,10 +2445,10 @@ void SwWW8ImplReader::StripNegativeAfterIndent(SwFrameFormat *pFlyFormat) void SwWW8ImplReader::StopApo() { - OSL_ENSURE(m_pWFlyPara, "no pWFlyPara to close"); - if (!m_pWFlyPara) + OSL_ENSURE(m_xWFlyPara, "no pWFlyPara to close"); + if (!m_xWFlyPara) return; - if (m_pWFlyPara->bGrafApo) + if (m_xWFlyPara->bGrafApo) { // image frame that has not been inserted: delete empty paragraph + attr JoinNode(*m_pPaM, true); @@ -2455,10 +2456,9 @@ void SwWW8ImplReader::StopApo() } else { - if (!m_pSFlyPara->pMainTextPos || !m_pWFlyPara) + if (!m_xSFlyPara->pMainTextPos) { - OSL_ENSURE( m_pSFlyPara->pMainTextPos, "StopApo: pMainTextPos ist 0" ); - OSL_ENSURE( m_pWFlyPara, "StopApo: pWFlyPara ist 0" ); + OSL_ENSURE( m_xSFlyPara->pMainTextPos, "StopApo: pMainTextPos ist 0" ); return; } @@ -2479,14 +2479,14 @@ void SwWW8ImplReader::StopApo() SwNodeIndex aPref(m_pPaM->GetPoint()->nNode, -1); SwTwips nNewWidth = - MoveOutsideFly(m_pSFlyPara->pFlyFormat, *m_pSFlyPara->pMainTextPos); + MoveOutsideFly(m_xSFlyPara->pFlyFormat, *m_xSFlyPara->pMainTextPos); if (nNewWidth) - m_pSFlyPara->BoxUpWidth(nNewWidth); + m_xSFlyPara->BoxUpWidth(nNewWidth); Color aBg(0xFE, 0xFF, 0xFF, 0xFF); //Transparent by default SwTextNode* pNd = aPref.GetNode().GetTextNode(); - if (pNd && m_pSFlyPara->pFlyFormat) + if (pNd && m_xSFlyPara->pFlyFormat) { /* #i582# @@ -2518,22 +2518,22 @@ void SwWW8ImplReader::StopApo() pNd->JoinNext(); } - if (m_pSFlyPara->pFlyFormat) - m_pSFlyPara->pFlyFormat->SetFormatAttr(SvxBrushItem(aBg, RES_BACKGROUND)); + if (m_xSFlyPara->pFlyFormat) + m_xSFlyPara->pFlyFormat->SetFormatAttr(SvxBrushItem(aBg, RES_BACKGROUND)); DeleteAnchorStack(); - m_pAnchorStck = m_pSFlyPara->pOldAnchorStck; + m_pAnchorStck = m_xSFlyPara->pOldAnchorStck; // When inserting a graphic into the fly frame using the auto // function, the extension of the SW-fly has to be set // manually as the SW fly has no auto function to adjust the // frame´s size. - if(m_pSFlyPara->nNewNetWidth > MINFLY && m_pSFlyPara->pFlyFormat) // BoxUpWidth ? + if (m_xSFlyPara->nNewNetWidth > MINFLY && m_xSFlyPara->pFlyFormat) // BoxUpWidth ? { - long nW = m_pSFlyPara->nNewNetWidth; - nW += m_pSFlyPara->nWidth - m_pSFlyPara->nNetWidth; // border for it - m_pSFlyPara->pFlyFormat->SetFormatAttr( - SwFormatFrameSize( m_pSFlyPara->eHeightFix, nW, m_pSFlyPara->nHeight ) ); + long nW = m_xSFlyPara->nNewNetWidth; + nW += m_xSFlyPara->nWidth - m_xSFlyPara->nNetWidth; // border for it + m_xSFlyPara->pFlyFormat->SetFormatAttr( + SwFormatFrameSize(m_xSFlyPara->eHeightFix, nW, m_xSFlyPara->nHeight)); } /* Word set *no* width meaning it's an automatic width. The @@ -2543,48 +2543,48 @@ void SwWW8ImplReader::StopApo() #i27204# Added AutoWidth setting. Left the old CalculateFlySize in place so that if the user unselects autowidth, the width doesn't max out */ - else if( !m_pWFlyPara->nSp28 && m_pSFlyPara->pFlyFormat) + else if (!m_xWFlyPara->nSp28 && m_xSFlyPara->pFlyFormat) { using namespace sw::util; - SfxItemSet aFlySet( m_pSFlyPara->pFlyFormat->GetAttrSet() ); + SfxItemSet aFlySet( m_xSFlyPara->pFlyFormat->GetAttrSet() ); SwFormatFrameSize aSize(ItemGet(aFlySet, RES_FRM_SIZE)); aFlySet.ClearItem(RES_FRM_SIZE); - CalculateFlySize(aFlySet, m_pSFlyPara->pMainTextPos->nNode, - m_pSFlyPara->nWidth); + CalculateFlySize(aFlySet, m_xSFlyPara->pMainTextPos->nNode, + m_xSFlyPara->nWidth); nNewWidth = ItemGet(aFlySet, RES_FRM_SIZE).GetWidth(); aSize.SetWidth(nNewWidth); aSize.SetWidthSizeType(ATT_VAR_SIZE); - m_pSFlyPara->pFlyFormat->SetFormatAttr(aSize); + m_xSFlyPara->pFlyFormat->SetFormatAttr(aSize); } - delete m_pSFlyPara->pMainTextPos; - m_pSFlyPara->pMainTextPos = nullptr; + delete m_xSFlyPara->pMainTextPos; + m_xSFlyPara->pMainTextPos = nullptr; // To create the SwFrames when inserting into an existing document, fltshell.cxx // will call pFlyFrame->MakeFrames() when setting the FltAnchor attribute } //#i8062# - if (m_pSFlyPara && m_pSFlyPara->pFlyFormat) - m_pFormatOfJustInsertedApo = m_pSFlyPara->pFlyFormat; + if (m_xSFlyPara && m_xSFlyPara->pFlyFormat) + m_pFormatOfJustInsertedApo = m_xSFlyPara->pFlyFormat; - DELETEZ( m_pSFlyPara ); - DELETEZ( m_pWFlyPara ); + m_xSFlyPara.reset(); + m_xWFlyPara.reset(); } // TestSameApo() returns if it's the same Apo or a different one bool SwWW8ImplReader::TestSameApo(const ApoTestResults &rApo, const WW8_TablePos *pTabPos) { - if( !m_pWFlyPara ) + if (!m_xWFlyPara) { - OSL_ENSURE( m_pWFlyPara, " Where is my pWFlyPara ? " ); + OSL_ENSURE(m_xWFlyPara, " Where is my pWFlyPara ? "); return true; } @@ -2600,7 +2600,7 @@ bool SwWW8ImplReader::TestSameApo(const ApoTestResults &rApo, aF.Read(rApo.m_nSprm29, m_pPlcxMan->GetPapPLCF()); aF.ApplyTabPos(pTabPos); - return aF == *m_pWFlyPara; + return aF == *m_xWFlyPara; } void SwWW8ImplReader::NewAttr( const SfxPoolItem& rAttr, @@ -4189,8 +4189,8 @@ void SwWW8ImplReader::Read_LineSpace( sal_uInt16, const sal_uInt8* pData, short aLSpc.SetLineSpaceRule( eLnSpc); } NewAttr( aLSpc ); - if( m_pSFlyPara ) - m_pSFlyPara->nLineSpace = nSpaceTw; // linespace for graphics APOs + if (m_xSFlyPara) + m_xSFlyPara->nLineSpace = nSpaceTw; // linespace for graphics APOs } //#i18519# AutoSpace value depends on Dop fDontUseHTMLAutoSpacing setting @@ -4821,8 +4821,7 @@ void SwWW8ImplReader::Read_Border(sal_uInt16 , const sal_uInt8*, short nLen) if( nBorder ) // Border { bool bIsB = IsBorder(aBrcs, true); - if (!InLocalApo() || !bIsB || - (m_pWFlyPara && !m_pWFlyPara->bBorderLines )) + if (!InLocalApo() || !bIsB || (m_xWFlyPara && !m_xWFlyPara->bBorderLines)) { // Do not turn *on* borders in APO, since otherwise // I get the Fly border twice; -- cgit