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 @@
#include <svl/itempool.hxx>
#include <svl/itemset.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp>
/*************************************************************************
UNO III Implementation
......@@ -242,7 +243,7 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn
{
// get the SfxPoolItem
const SfxPoolItem* pItem = 0;
SfxPoolItem *pNewItem = 0;
boost::scoped_ptr<SfxPoolItem> pNewItem;
SfxItemState eState = rSet.GetItemState( rEntry.nWID, true, &pItem );
if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID )
pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID);
......@@ -253,23 +254,21 @@ void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEn
if(FillItem(aSet, rEntry.nWID, false))
{
const SfxPoolItem &rItem = aSet.Get(rEntry.nWID);
pNewItem = rItem.Clone();
pNewItem.reset(rItem.Clone());
}
}
if(!pNewItem && pItem)
{
pNewItem = pItem->Clone();
pNewItem.reset(pItem->Clone());
}
if(pNewItem)
{
if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) )
{
DELETEZ(pNewItem);
throw IllegalArgumentException();
}
// apply new item
rSet.Put( *pNewItem, rEntry.nWID );
delete pNewItem;
}
}
......
......@@ -28,6 +28,7 @@
#include <svl/brdcst.hxx>
#include <svl/filerec.hxx>
#include "poolio.hxx"
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
/**
......@@ -207,11 +208,10 @@ SvStream &SfxItemPool::Store(SvStream &rStream) const
{
sal_uLong nMark = rStream.Tell();
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();
SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" );
SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" );
delete pClone;
}
#endif
}
......
This diff is collapsed.
......@@ -46,6 +46,7 @@
#include <svl/nfsymbol.hxx>
#include <cmath>
#include <boost/scoped_ptr.hpp>
using namespace svt;
......@@ -1853,11 +1854,11 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
// Parse new ones etc.
OUString aStr( sFormatstring );
sal_Int32 nCheckPos = 0;
SvNumberformat* pFormat = new SvNumberformat( aStr, &rScan, &rISc,
nCheckPos, maLocale.meLanguage, bStandard );
boost::scoped_ptr<SvNumberformat> pFormat(new SvNumberformat( aStr, &rScan, &rISc,
nCheckPos, maLocale.meLanguage, bStandard ));
DBG_ASSERT( !nCheckPos, "SvNumberformat::Load: NewCurrencyRescan nCheckPos" );
ImpCopyNumberformat( *pFormat );
delete pFormat;
pFormat.reset();
// Recover states
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