summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-01-30 16:46:22 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-01-30 16:55:05 +0900
commit9e9a59293a6538f4b41ba6892cf3f84967003000 (patch)
treee4a869a948089ab3e736aec3df722021bff18965
parent0d8679da48ca7b9cdde55954b58c468c16091941 (diff)
Avoid resource leaks in case of exception
Change-Id: I4461ab619a71fcbe18d4d805a964fd358e857eda
-rw-r--r--sw/source/core/crsr/findattr.cxx9
-rw-r--r--sw/source/core/crsr/findfmt.cxx5
-rw-r--r--sw/source/core/doc/docbasic.cxx16
-rw-r--r--sw/source/ui/dochdl/swdtflvr.cxx4
4 files changed, 14 insertions, 20 deletions
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 38aac541ea18..9ebd1a2671c0 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -41,6 +41,7 @@
#include <swundo.hxx>
#include <crsskip.hxx>
#include <boost/optional.hpp>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
@@ -879,7 +880,7 @@ bool SwPaM::Find( const SfxPoolItem& rAttr, bool bValue, SwMoveFn fnMove,
const sal_uInt16 nWhich = rAttr.Which();
bool bCharAttr = isCHRATR(nWhich) || isTXTATR(nWhich);
- SwPaM* pPam = MakeRegion( fnMove, pRegion );
+ boost::scoped_ptr<SwPaM> pPam(MakeRegion( fnMove, pRegion ));
bool bFound = false;
sal_Bool bFirst = sal_True;
@@ -895,7 +896,6 @@ bool SwPaM::Find( const SfxPoolItem& rAttr, bool bValue, SwMoveFn fnMove,
{
if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, sal_False ))
{
- delete pPam;
return false;
}
SwCntntNode *pNd = pPam->GetCntntNode();
@@ -950,7 +950,6 @@ bool SwPaM::Find( const SfxPoolItem& rAttr, bool bValue, SwMoveFn fnMove,
if( bFound && !bSrchForward )
Exchange();
- delete pPam;
return bFound;
}
@@ -959,7 +958,7 @@ typedef int (*FnSearchAttr)( const SwTxtNode&, SwAttrCheckArr&, SwPaM& );
bool SwPaM::Find( const SfxItemSet& rSet, bool bNoColls, SwMoveFn fnMove,
const SwPaM *pRegion, bool bInReadOnly, bool bMoveFirst )
{
- SwPaM* pPam = MakeRegion( fnMove, pRegion );
+ boost::scoped_ptr<SwPaM> pPam(MakeRegion( fnMove, pRegion ));
bool bFound = false;
sal_Bool bFirst = sal_True;
@@ -985,7 +984,6 @@ bool SwPaM::Find( const SfxItemSet& rSet, bool bNoColls, SwMoveFn fnMove,
{
if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, sal_False ))
{
- delete pPam;
return false;
}
SwCntntNode *pNd = pPam->GetCntntNode();
@@ -1043,7 +1041,6 @@ bool SwPaM::Find( const SfxItemSet& rSet, bool bNoColls, SwMoveFn fnMove,
if( bFound && !bSrchForward )
Exchange();
- delete pPam;
return bFound;
}
diff --git a/sw/source/core/crsr/findfmt.cxx b/sw/source/core/crsr/findfmt.cxx
index e9c30ebf8d45..d73f5d902a8e 100644
--- a/sw/source/core/crsr/findfmt.cxx
+++ b/sw/source/core/crsr/findfmt.cxx
@@ -19,13 +19,14 @@
#include <doc.hxx>
#include <pamtyp.hxx>
+#include <boost/scoped_ptr.hpp>
bool SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
const SwPaM *pRegion, bool bInReadOnly )
{
bool bFound = false;
const bool bSrchForward = (fnMove == fnMoveForward);
- SwPaM* pPam = MakeRegion( fnMove, pRegion );
+ boost::scoped_ptr<SwPaM> pPam(MakeRegion( fnMove, pRegion ));
// if at beginning/end then move it out of the node
if( bSrchForward
@@ -34,7 +35,6 @@ bool SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
{
if( !(*fnMove->fnNds)( &pPam->GetPoint()->nNode, sal_False ))
{
- delete pPam;
return false;
}
SwCntntNode *pNd = pPam->GetPoint()->nNode.GetNode().GetCntntNode();
@@ -65,7 +65,6 @@ bool SwPaM::Find( const SwFmt& rFmt, SwMoveFn fnMove,
break;
}
}
- delete pPam;
return bFound;
}
diff --git a/sw/source/core/doc/docbasic.cxx b/sw/source/core/doc/docbasic.cxx
index 15fcf5ff3950..4b2fdfe2d9f9 100644
--- a/sw/source/core/doc/docbasic.cxx
+++ b/sw/source/core/doc/docbasic.cxx
@@ -31,6 +31,7 @@
#include <doc.hxx>
#include <docsh.hxx>
#include <swevent.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno;
@@ -98,17 +99,17 @@ bool SwDoc::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
break;
case EXTENDED_STYPE:
{
- Sequence<Any> *pUnoArgs = 0;
+ boost::scoped_ptr<Sequence<Any> > pUnoArgs;
if( pArgs )
{
// better to rename the local function to lcl_translateBasic2Uno and
// a much shorter routine can be found in sfx2/source/doc/objmisc.cxx
- pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
+ pUnoArgs.reset(lcl_docbasic_convertArgs( *pArgs ));
}
if (!pUnoArgs)
{
- pUnoArgs = new Sequence< Any > (0);
+ pUnoArgs.reset(new Sequence< Any > (0));
}
// TODO - return value is not handled
@@ -122,7 +123,6 @@ bool SwDoc::ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs )
eErr = mpDocShell->CallXScript(
rMacro.GetMacName(), *pUnoArgs, aRet, aOutArgsIndex, aOutArgs);
- delete pUnoArgs;
break;
}
}
@@ -210,16 +210,16 @@ sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEve
}
else if( EXTENDED_STYPE == rMacro.GetScriptType() )
{
- Sequence<Any> *pUnoArgs = 0;
+ boost::scoped_ptr<Sequence<Any> > pUnoArgs;
if( pArgs )
{
- pUnoArgs = lcl_docbasic_convertArgs( *pArgs );
+ pUnoArgs.reset(lcl_docbasic_convertArgs( *pArgs ));
}
if (!pUnoArgs)
{
- pUnoArgs = new Sequence <Any> (0);
+ pUnoArgs.reset(new Sequence <Any> (0));
}
Any aRet;
@@ -231,8 +231,6 @@ sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEve
nRet += 0 == mpDocShell->CallXScript(
rMacro.GetMacName(), *pUnoArgs,aRet, aOutArgsIndex, aOutArgs) ? 1 : 0;
-
- delete pUnoArgs;
}
// JavaScript calls are ignored
}
diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx
index f4e82f11870b..5bd3dd78c940 100644
--- a/sw/source/ui/dochdl/swdtflvr.cxx
+++ b/sw/source/ui/dochdl/swdtflvr.cxx
@@ -670,12 +670,12 @@ sal_Bool SwTransferable::WriteObject( SotStorageStreamRef& xStream,
if ( xTransact.is() )
xTransact->commit();
- SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
+ boost::scoped_ptr<SvStream> pSrcStm(::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ));
if( pSrcStm )
{
xStream->SetBufferSize( 0xff00 );
xStream->WriteStream( *pSrcStm );
- delete pSrcStm;
+ pSrcStm.reset();
}
bRet = sal_True;