[Libreoffice-commits] .: sw/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Wed Sep 7 13:39:41 PDT 2011


 sw/source/core/inc/UndoTable.hxx |    9 ++++++---
 sw/source/core/undo/untbl.cxx    |   19 +++++--------------
 2 files changed, 11 insertions(+), 17 deletions(-)

New commits:
commit f2326368c0a8d6ee56fea10ffc28d16a249b6747
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Sep 7 18:03:50 2011 +0200

    SwUndoTblNdsChg::pDelSects was used unitialized.
    
    sw/qa/unoapi checks failed because of this.
    
    Changed both pDelSects and pNewSttNds to auto_ptrs to clean up resource handling here;
    explicitly made SwUndoTblNdsChg noncopyable to avoid auto_ptr-stealing.

diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx
index a661bc2..d3a1a9a 100644
--- a/sw/source/core/inc/UndoTable.hxx
+++ b/sw/source/core/inc/UndoTable.hxx
@@ -30,11 +30,14 @@
 
 #include <undobj.hxx>
 
+#include <memory>
 #include <vector>
 #include <set>
 #include <swtypes.hxx>
 #include <itabenum.hxx>
 
+#include "boost/noncopyable.hpp"
+
 class SfxItemSet;
 
 struct SwSaveRowSpan;
@@ -171,7 +174,7 @@ public:
     void SaveBoxCntnt( const SwTableBox& rBox );
 };
 
-class SwUndoTblNdsChg : public SwUndo
+class SwUndoTblNdsChg : public SwUndo, private boost::noncopyable
 {
     _SaveTable* pSaveTbl;
     std::set<sal_uLong> aBoxes;
@@ -182,8 +185,8 @@ class SwUndoTblNdsChg : public SwUndo
         _BoxMove(sal_uLong idx, bool moved=false) : index(idx), hasMoved(moved) {};
         bool operator<(const _BoxMove other) const { return index < other.index; };
     };
-    std::set<_BoxMove> *pNewSttNds;
-    SwUndoSaveSections *pDelSects;
+    std::auto_ptr< std::set<_BoxMove> > pNewSttNds;
+    std::auto_ptr< SwUndoSaveSections > pDelSects;
     long nMin, nMax;        // for redo of delete column
     sal_uLong nSttNode, nCurrBox;
     sal_uInt16 nCount, nRelDiff, nAbsDiff, nSetColType;
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 1f430a0..8f3563f 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -1551,8 +1551,6 @@ SwUndoTblNdsChg::SwUndoTblNdsChg( SwUndoId nAction,
     bFlag( bFlg ),
     bSameHeight( bSmHght )
 {
-    pNewSttNds = 0;
-
     const SwTable& rTbl = rTblNd.GetTable();
     pSaveTbl = new _SaveTable( rTbl );
 
@@ -1572,8 +1570,6 @@ SwUndoTblNdsChg::SwUndoTblNdsChg( SwUndoId nAction,
     bFlag( sal_False ),
     bSameHeight( sal_False )
 {
-    pNewSttNds = 0;
-
     const SwTable& rTbl = rTblNd.GetTable();
     pSaveTbl = new _SaveTable( rTbl );
 
@@ -1594,11 +1590,6 @@ void SwUndoTblNdsChg::ReNewBoxes( const SwSelBoxes& rBoxes )
 SwUndoTblNdsChg::~SwUndoTblNdsChg()
 {
     delete pSaveTbl;
-
-    if( IsDelBox() )
-        delete pDelSects;
-    else
-        delete pNewSttNds;
 }
 
 void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
@@ -1610,7 +1601,7 @@ void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
     sal_uInt16 i;
 
     OSL_ENSURE( ! IsDelBox(), "falsche Action" );
-    pNewSttNds = new std::set<_BoxMove>;
+    pNewSttNds.reset( new std::set<_BoxMove> );
 
     for( n = 0, i = 0; n < rOld.Count(); ++i )
     {
@@ -1663,7 +1654,7 @@ void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
     const SwTableSortBoxes& rTblBoxes = rTbl.GetTabSortBoxes();
 
     OSL_ENSURE( ! IsDelBox(), "falsche Action" );
-    pNewSttNds = new std::set<_BoxMove>;
+    pNewSttNds.reset( new std::set<_BoxMove> );
 
     OSL_ENSURE( rTbl.IsNewModel() || rOld.Count() + nCount * rBoxes.Count() == rTblBoxes.Count(),
         "unexpected boxes" );
@@ -1739,8 +1730,8 @@ void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
 void SwUndoTblNdsChg::SaveSection( SwStartNode* pSttNd )
 {
     OSL_ENSURE( IsDelBox(), "falsche Action" );
-    if( !pDelSects )
-        pDelSects = new SwUndoSaveSections( 10, 5 );
+    if( pDelSects.get() == NULL )
+        pDelSects.reset( new SwUndoSaveSections( 10, 5 ) );
 
     SwTableNode* pTblNd = pSttNd->FindTableNode();
     SwUndoSaveSection* pSave = new SwUndoSaveSection;
@@ -1965,7 +1956,7 @@ void SwUndoTblNdsChg::RedoImpl(::sw::UndoRedoContext & rContext)
 
             if( pUndo )
             {
-                pDelSects->Insert( pUndo->pDelSects, 0 );
+                pDelSects->Insert( pUndo->pDelSects.get(), 0 );
                 pUndo->pDelSects->Remove( 0, pUndo->pDelSects->Count() );
 
                 delete pUndo;


More information about the Libreoffice-commits mailing list