Kaydet (Commit) 4468ab0e authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: I1dd003bc984a11d6d71c92aae44accc9d358db0c
üst 6bcf07ec
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <svl/itempool.hxx> #include <svl/itempool.hxx>
#include <svl/itemset.hxx> #include <svl/itemset.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
/************************************************************************* /*************************************************************************
UNO III Implementation UNO III Implementation
...@@ -242,7 +243,7 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn ...@@ -242,7 +243,7 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn
{ {
// get the SfxPoolItem // get the SfxPoolItem
const SfxPoolItem* pItem = 0; const SfxPoolItem* pItem = 0;
SfxPoolItem *pNewItem = 0; boost::scoped_ptr<SfxPoolItem> pNewItem;
SfxItemState eState = rSet.GetItemState( rEntry.nWID, true, &pItem ); SfxItemState eState = rSet.GetItemState( rEntry.nWID, true, &pItem );
if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID ) if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID )
pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID); pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID);
...@@ -253,23 +254,21 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn ...@@ -253,23 +254,21 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn
if(FillItem(aSet, rEntry.nWID, false)) if(FillItem(aSet, rEntry.nWID, false))
{ {
const SfxPoolItem &rItem = aSet.Get(rEntry.nWID); const SfxPoolItem &rItem = aSet.Get(rEntry.nWID);
pNewItem = rItem.Clone(); pNewItem.reset(rItem.Clone());
} }
} }
if(!pNewItem && pItem) if(!pNewItem && pItem)
{ {
pNewItem = pItem->Clone(); pNewItem.reset(pItem->Clone());
} }
if(pNewItem) if(pNewItem)
{ {
if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) ) if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) )
{ {
DELETEZ(pNewItem);
throw IllegalArgumentException(); throw IllegalArgumentException();
} }
// apply new item // apply new item
rSet.Put( *pNewItem, rEntry.nWID ); rSet.Put( *pNewItem, rEntry.nWID );
delete pNewItem;
} }
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <svl/brdcst.hxx> #include <svl/brdcst.hxx>
#include <svl/filerec.hxx> #include <svl/filerec.hxx>
#include "poolio.hxx" #include "poolio.hxx"
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
/** /**
...@@ -207,11 +208,10 @@ SvStream &SfxItemPool::Store(SvStream &rStream) const ...@@ -207,11 +208,10 @@ SvStream &SfxItemPool::Store(SvStream &rStream) const
{ {
sal_uLong nMark = rStream.Tell(); sal_uLong nMark = rStream.Tell();
rStream.Seek( nItemStartPos + sizeof(sal_uInt16) ); rStream.Seek( nItemStartPos + sizeof(sal_uInt16) );
SfxPoolItem *pClone = pItem->Create(rStream, nItemVersion ); boost::scoped_ptr<SfxPoolItem> pClone(pItem->Create(rStream, nItemVersion ));
sal_uInt16 nWh = pItem->Which(); sal_uInt16 nWh = pItem->Which();
SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" ); SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" );
SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" ); SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" );
delete pClone;
} }
#endif #endif
} }
......
This diff is collapsed.
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <svl/nfsymbol.hxx> #include <svl/nfsymbol.hxx>
#include <cmath> #include <cmath>
#include <boost/scoped_ptr.hpp>
using namespace svt; using namespace svt;
...@@ -1853,11 +1854,11 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream, ...@@ -1853,11 +1854,11 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
// Parse new ones etc. // Parse new ones etc.
OUString aStr( sFormatstring ); OUString aStr( sFormatstring );
sal_Int32 nCheckPos = 0; sal_Int32 nCheckPos = 0;
SvNumberformat* pFormat = new SvNumberformat( aStr, &rScan, &rISc, boost::scoped_ptr<SvNumberformat> pFormat(new SvNumberformat( aStr, &rScan, &rISc,
nCheckPos, maLocale.meLanguage, bStandard ); nCheckPos, maLocale.meLanguage, bStandard ));
DBG_ASSERT( !nCheckPos, "SvNumberformat::Load: NewCurrencyRescan nCheckPos" ); DBG_ASSERT( !nCheckPos, "SvNumberformat::Load: NewCurrencyRescan nCheckPos" );
ImpCopyNumberformat( *pFormat ); ImpCopyNumberformat( *pFormat );
delete pFormat; pFormat.reset();
// Recover states // Recover states
eType |= nDefined; eType |= nDefined;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment