[Libreoffice-commits] core.git: sc/source
Takeshi Abe
tabe at fixedpoint.jp
Fri May 2 00:42:18 PDT 2014
sc/source/filter/excel/xestream.cxx | 10 ++++-----
sc/source/filter/excel/xistream.cxx | 25 ++++++++++--------------
sc/source/filter/lotus/lotform.cxx | 9 +++-----
sc/source/ui/docshell/docsh6.cxx | 5 +---
sc/source/ui/sidebar/CellBorderStyleControl.cxx | 25 ++++++++++++------------
sc/source/ui/undo/undoblk.cxx | 9 ++++----
sc/source/ui/undo/undotab.cxx | 15 ++++++--------
7 files changed, 47 insertions(+), 51 deletions(-)
New commits:
commit f3816179a0b81c7d122006435a1ebf518309c392
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Fri May 2 16:35:17 2014 +0900
Avoid possible memory leaks in case of exceptions
Change-Id: Id1c7cb886a892bf0ce7be6774be5408afad44432
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 946e05f..6f5c7b4 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -56,6 +56,7 @@
#include <sfx2/app.hxx>
#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <boost/scoped_array.hpp>
#define DEBUG_XL_ENCRYPTION 0
@@ -284,19 +285,18 @@ void XclExpStream::CopyFromStream(SvStream& rInStrm, sal_uInt64 const nBytes)
if( nBytesLeft > 0 )
{
const sal_Size nMaxBuffer = 4096;
- sal_uInt8 *const pBuffer =
- new sal_uInt8[ ::std::min<sal_Size>(nBytesLeft, nMaxBuffer) ];
+ boost::scoped_array<sal_uInt8> pBuffer(
+ new sal_uInt8[ ::std::min<sal_Size>(nBytesLeft, nMaxBuffer) ]);
bool bValid = true;
while( bValid && (nBytesLeft > 0) )
{
sal_Size nWriteLen = ::std::min<sal_Size>(nBytesLeft, nMaxBuffer);
- rInStrm.Read( pBuffer, nWriteLen );
- sal_Size nWriteRet = Write( pBuffer, nWriteLen );
+ rInStrm.Read( pBuffer.get(), nWriteLen );
+ sal_Size nWriteRet = Write( pBuffer.get(), nWriteLen );
bValid = (nWriteLen == nWriteRet);
nBytesLeft -= nWriteRet;
}
- delete[] pBuffer;
}
}
diff --git a/sc/source/filter/excel/xistream.cxx b/sc/source/filter/excel/xistream.cxx
index 5419b83..ceaf16a 100644
--- a/sc/source/filter/excel/xistream.cxx
+++ b/sc/source/filter/excel/xistream.cxx
@@ -25,6 +25,7 @@
#include "xiroot.hxx"
#include <vector>
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star;
@@ -790,20 +791,18 @@ sal_Size XclImpStream::CopyToStream( SvStream& rOutStrm, sal_Size nBytes )
if( mbValid && (nBytes > 0) )
{
const sal_Size nMaxBuffer = 4096;
- sal_uInt8* pnBuffer = new sal_uInt8[ ::std::min( nBytes, nMaxBuffer ) ];
+ boost::scoped_array<sal_uInt8> pnBuffer(new sal_uInt8[ ::std::min( nBytes, nMaxBuffer ) ]);
sal_Size nBytesLeft = nBytes;
while( mbValid && (nBytesLeft > 0) )
{
sal_Size nReadSize = ::std::min( nBytesLeft, nMaxBuffer );
- nRet += Read( pnBuffer, nReadSize );
+ nRet += Read( pnBuffer.get(), nReadSize );
// writing more bytes than read results in invalid memory access
SAL_WARN_IF(nRet != nReadSize, "sc", "read less bytes than requested");
- rOutStrm.Write( pnBuffer, nReadSize );
+ rOutStrm.Write( pnBuffer.get(), nReadSize );
nBytesLeft -= nReadSize;
}
-
- delete[] pnBuffer;
}
return nRet;
}
@@ -881,7 +880,7 @@ OUString XclImpStream::ReadRawUniString( sal_uInt16 nChars, bool b16Bit )
sal_uInt16 nCharsLeft = nChars;
sal_uInt16 nReadSize;
- sal_Unicode* pcBuffer = new sal_Unicode[ nCharsLeft + 1 ];
+ boost::scoped_array<sal_Unicode> pcBuffer(new sal_Unicode[ nCharsLeft + 1 ]);
while( IsValid() && (nCharsLeft > 0) )
{
@@ -894,8 +893,8 @@ OUString XclImpStream::ReadRawUniString( sal_uInt16 nChars, bool b16Bit )
else
nReadSize = GetMaxRawReadSize( nCharsLeft );
- sal_Unicode* pcUniChar = pcBuffer;
- sal_Unicode* pcEndChar = pcBuffer + nReadSize;
+ sal_Unicode* pcUniChar = pcBuffer.get();
+ sal_Unicode* pcEndChar = pcBuffer.get() + nReadSize;
if( b16Bit )
{
@@ -917,14 +916,13 @@ OUString XclImpStream::ReadRawUniString( sal_uInt16 nChars, bool b16Bit )
}
*pcEndChar = '\0';
- aRet += OUString( pcBuffer );
+ aRet += OUString( pcBuffer.get() );
nCharsLeft = nCharsLeft - nReadSize;
if( nCharsLeft > 0 )
JumpToNextStringContinue( b16Bit );
}
- delete[] pcBuffer;
return aRet;
}
@@ -988,11 +986,10 @@ void XclImpStream::IgnoreUniString( sal_uInt16 nChars )
OUString XclImpStream::ReadRawByteString( sal_uInt16 nChars )
{
- sal_Char* pcBuffer = new sal_Char[ nChars + 1 ];
- sal_uInt16 nCharsRead = ReadRawData( pcBuffer, nChars );
+ boost::scoped_array<sal_Char> pcBuffer(new sal_Char[ nChars + 1 ]);
+ sal_uInt16 nCharsRead = ReadRawData( pcBuffer.get(), nChars );
pcBuffer[ nCharsRead ] = '\0';
- OUString aRet( pcBuffer, strlen(pcBuffer), mrRoot.GetTextEncoding() );
- delete[] pcBuffer;
+ OUString aRet( pcBuffer.get(), strlen(pcBuffer.get()), mrRoot.GetTextEncoding() );
return aRet;
}
diff --git a/sc/source/filter/lotus/lotform.cxx b/sc/source/filter/lotus/lotform.cxx
index f767504..aeeff6e 100644
--- a/sc/source/filter/lotus/lotform.cxx
+++ b/sc/source/filter/lotus/lotform.cxx
@@ -28,6 +28,7 @@
#include <math.h>
#include <comphelper/string.hxx>
+#include <boost/scoped_array.hpp>
extern WKTYP eTyp;
@@ -566,15 +567,13 @@ ConvErr LotusToSc::Convert( const ScTokenArray*& rpErg, sal_Int32& rRest,
if( nStrLen )
{
- sal_Char* p = new (::std::nothrow) sal_Char[ nStrLen + 1 ];
+ boost::scoped_array<sal_Char> p(new (::std::nothrow) sal_Char[ nStrLen + 1 ]);
if (p)
{
- aIn.Read( p, nStrLen );
+ aIn.Read( p.get(), nStrLen );
p[ nStrLen ] = 0x00;
- DoFunc( ocNoName, nAnz, p );
-
- delete[] p;
+ DoFunc( ocNoName, nAnz, p.get() );
}
else
DoFunc( ocNoName, nAnz, NULL );
diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx
index 87404c7..7dd8d0e 100644
--- a/sc/source/ui/docshell/docsh6.cxx
+++ b/sc/source/ui/docshell/docsh6.cxx
@@ -42,6 +42,7 @@
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/util/XChangesBatch.hpp>
+#include <boost/scoped_array.hpp>
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::lang::XMultiServiceFactory;
@@ -289,7 +290,7 @@ void ScDocShell::LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellS
if ( nSourceCount == 0 )
return; // no source styles
- ScStylePair* pStyles = new ScStylePair[ nSourceCount ];
+ boost::scoped_array<ScStylePair> pStyles(new ScStylePair[ nSourceCount ]);
sal_uInt16 nFound = 0;
// first create all new styles
@@ -333,8 +334,6 @@ void ScDocShell::LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellS
lcl_AdjustPool( GetStyleSheetPool() ); // adjust SetItems
UpdateAllRowHeights();
PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID | PAINT_LEFT ); // Paint
-
- delete[] pStyles;
}
diff --git a/sc/source/ui/sidebar/CellBorderStyleControl.cxx b/sc/source/ui/sidebar/CellBorderStyleControl.cxx
index 2d0ec3d..da14577 100644
--- a/sc/source/ui/sidebar/CellBorderStyleControl.cxx
+++ b/sc/source/ui/sidebar/CellBorderStyleControl.cxx
@@ -29,6 +29,7 @@
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <editeng/lineitem.hxx>
+#include <boost/scoped_ptr.hpp>
namespace sc { namespace sidebar {
@@ -284,8 +285,8 @@ IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox)
SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
- editeng::SvxBorderLine *pTop = 0 ,
- *pBottom = 0 ;
+ boost::scoped_ptr<editeng::SvxBorderLine> pTop;
+ boost::scoped_ptr<editeng::SvxBorderLine> pBottom;
sal_uInt8 nValidFlags = 0;
using namespace ::com::sun::star::table::BorderLineStyle;
@@ -294,29 +295,29 @@ IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox)
switch ( nId )
{
case TBI_BORDER3_S1:
- pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
+ pBottom.reset(new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 ));
nValidFlags |= FRM_VALID_BOTTOM;
break;
case TBI_BORDER3_S2:
- pBottom = new editeng::SvxBorderLine(NULL);
+ pBottom.reset(new editeng::SvxBorderLine(NULL));
pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
nValidFlags |= FRM_VALID_BOTTOM;
break;
case TBI_BORDER3_S3:
- pBottom = new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 );
- pTop = new editeng::SvxBorderLine(NULL, 1);
+ pBottom.reset(new editeng::SvxBorderLine(NULL, DEF_LINE_WIDTH_2 ));
+ pTop.reset(new editeng::SvxBorderLine(NULL, 1));
nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
break;
case TBI_BORDER3_S4:
- pBottom = new editeng::SvxBorderLine(NULL);
+ pBottom.reset(new editeng::SvxBorderLine(NULL));
pBottom->GuessLinesWidths(DOUBLE, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_0, DEF_LINE_WIDTH_1);
- pTop = new editeng::SvxBorderLine(NULL, 1);
+ pTop.reset(new editeng::SvxBorderLine(NULL, 1));
nValidFlags |= FRM_VALID_BOTTOM|FRM_VALID_TOP;
break;
}
- aBorderOuter.SetLine( pTop, BOX_LINE_TOP );
- aBorderOuter.SetLine( pBottom, BOX_LINE_BOTTOM );
+ aBorderOuter.SetLine( pTop.get(), BOX_LINE_TOP );
+ aBorderOuter.SetLine( pBottom.get(), BOX_LINE_BOTTOM );
aBorderOuter.SetLine( NULL, BOX_LINE_LEFT );
aBorderOuter.SetLine( NULL, BOX_LINE_RIGHT );
@@ -331,8 +332,8 @@ IMPL_LINK(CellBorderStyleControl, TB3SelectHdl, ToolBox *, pToolBox)
mrCellAppearancePropertyPanel.GetBindings()->GetDispatcher()->Execute(SID_ATTR_BORDER, SFX_CALLMODE_RECORD, &aBorderOuter, &aBorderInner, 0L);
- delete pTop;
- delete pBottom;
+ pTop.reset();
+ pBottom.reset();
mrCellAppearancePropertyPanel.EndCellBorderStylePopupMode();
return 0;
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 4472e94..fefa95f 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -51,6 +51,7 @@
#include <refhint.hxx>
#include <set>
+#include <boost/scoped_ptr.hpp>
// STATIC DATA -----------------------------------------------------------
@@ -1284,7 +1285,7 @@ void ScUndoDragDrop::Redo()
BeginRedo();
ScDocument* pDoc = pDocShell->GetDocument();
- ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
+ boost::scoped_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP ));
EnableDrawAdjust( pDoc, false ); //! include in ScBlockUndo?
@@ -1312,7 +1313,7 @@ void ScUndoDragDrop::Redo()
// do not clone objects and note captions into clipdoc (see above)
// but at least copy notes
ScClipParam aClipParam(aSrcRange, bCut);
- pDoc->CopyToClip(aClipParam, pClipDoc, &aSourceMark, false, bKeepScenarioFlags, false, true);
+ pDoc->CopyToClip(aClipParam, pClipDoc.get(), &aSourceMark, false, bKeepScenarioFlags, false, true);
if (bCut)
{
@@ -1330,7 +1331,7 @@ void ScUndoDragDrop::Redo()
bool bIncludeFiltered = bCut;
// TODO: restore old note captions instead of cloning new captions...
- pDoc->CopyFromClip( aDestRange, aDestMark, IDF_ALL & ~IDF_OBJECTS, NULL, pClipDoc, true, false, bIncludeFiltered );
+ pDoc->CopyFromClip( aDestRange, aDestMark, IDF_ALL & ~IDF_OBJECTS, NULL, pClipDoc.get(), true, false, bIncludeFiltered );
if (bCut)
for (nTab=aSrcRange.aStart.Tab(); nTab<=aSrcRange.aEnd.Tab(); nTab++)
@@ -1353,7 +1354,7 @@ void ScUndoDragDrop::Redo()
SetChangeTrack();
- delete pClipDoc;
+ pClipDoc.reset();
ShowTable( aDestRange.aStart.Tab() );
RedoSdrUndoAction( pDrawUndo ); //! include in ScBlockUndo?
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index f46a034..816e2b8 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -48,6 +48,7 @@
#include "scresid.hxx"
#include <vector>
+#include <boost/scoped_ptr.hpp>
extern bool bDrawIsInUndo; // somewhere as member!
@@ -512,8 +513,8 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
if (bUndo) // UnDo
{
size_t i = mpNewTabs->size();
- ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
- i * pDoc->GetCodeCount());
+ boost::scoped_ptr<ScProgress> pProgress(new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
+ i * pDoc->GetCodeCount()));
for (; i > 0; --i)
{
SCTAB nDestTab = (*mpNewTabs)[i-1];
@@ -521,7 +522,7 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
if (nDestTab > MAXTAB) // appended ?
nDestTab = pDoc->GetTableCount() - 1;
- pDoc->MoveTab( nDestTab, nOldTab, pProgress );
+ pDoc->MoveTab( nDestTab, nOldTab, pProgress.get() );
pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
pViewShell->SetTabNo( nOldTab, true );
if (mpOldNames)
@@ -530,13 +531,12 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
pDoc->RenameTab(nOldTab, rOldName);
}
}
- delete pProgress;
}
else
{
size_t n = mpNewTabs->size();
- ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
- n * pDoc->GetCodeCount());
+ boost::scoped_ptr<ScProgress> pProgress(new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
+ n * pDoc->GetCodeCount()));
for (size_t i = 0; i < n; ++i)
{
SCTAB nDestTab = (*mpNewTabs)[i];
@@ -545,7 +545,7 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
if (nDestTab > MAXTAB) // appended ?
nDestTab = pDoc->GetTableCount() - 1;
- pDoc->MoveTab( nOldTab, nNewTab, pProgress );
+ pDoc->MoveTab( nOldTab, nNewTab, pProgress.get() );
pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
pViewShell->SetTabNo( nDestTab, true );
if (mpNewNames)
@@ -554,7 +554,6 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
pDoc->RenameTab(nNewTab, rNewName);
}
}
- delete pProgress;
}
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
More information about the Libreoffice-commits
mailing list