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
} }
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <math.h> #include <math.h>
#include <limits> #include <limits>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -685,7 +686,7 @@ void SvNumberFormatter::DeleteEntry(sal_uInt32 nKey) ...@@ -685,7 +686,7 @@ void SvNumberFormatter::DeleteEntry(sal_uInt32 nKey)
bool SvNumberFormatter::Load( SvStream& rStream ) bool SvNumberFormatter::Load( SvStream& rStream )
{ {
LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType(); LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType();
SvNumberFormatter* pConverter = NULL; boost::scoped_ptr<SvNumberFormatter> pConverter;
ImpSvNumMultipleReadHeader aHdr( rStream ); ImpSvNumMultipleReadHeader aHdr( rStream );
sal_uInt16 nVersion; sal_uInt16 nVersion;
...@@ -725,7 +726,7 @@ bool SvNumberFormatter::Load( SvStream& rStream ) ...@@ -725,7 +726,7 @@ bool SvNumberFormatter::Load( SvStream& rStream )
// different SYSTEM locale // different SYSTEM locale
if ( !pConverter ) if ( !pConverter )
{ {
pConverter = new SvNumberFormatter( m_xContext, eSysLang ); pConverter.reset(new SvNumberFormatter( m_xContext, eSysLang ));
} }
pEntry->ConvertLanguage( *pConverter, eSaveSysLang, eLoadSysLang, true ); pEntry->ConvertLanguage( *pConverter, eSaveSysLang, eLoadSysLang, true );
} }
...@@ -763,10 +764,7 @@ bool SvNumberFormatter::Load( SvStream& rStream ) ...@@ -763,10 +764,7 @@ bool SvNumberFormatter::Load( SvStream& rStream )
aHdr.EndEntry(); aHdr.EndEntry();
} }
if ( pConverter ) pConverter.reset();
{
delete pConverter;
}
// generate additional i18n standard formats for all used locales // generate additional i18n standard formats for all used locales
LanguageType eOldLanguage = ActLnge; LanguageType eOldLanguage = ActLnge;
...@@ -1562,11 +1560,11 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, ...@@ -1562,11 +1560,11 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString,
eLnge = ActLnge; eLnge = ActLnge;
sal_Int32 nCheckPos = -1; sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString; OUString sTmpString = sFormatString;
SvNumberformat* p_Entry = new SvNumberformat(sTmpString, boost::scoped_ptr<SvNumberformat> p_Entry(new SvNumberformat(sTmpString,
pFormatScanner, pFormatScanner,
pStringScanner, pStringScanner,
nCheckPos, nCheckPos,
eLnge); eLnge));
if (nCheckPos == 0) // String ok if (nCheckPos == 0) // String ok
{ {
sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary
...@@ -1587,12 +1585,10 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, ...@@ -1587,12 +1585,10 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString,
p_Entry->SetStarFormatSupport( false ); p_Entry->SetStarFormatSupport( false );
} }
} }
delete p_Entry;
return true; return true;
} }
else else
{ {
delete p_Entry;
return false; return false;
} }
} }
...@@ -1625,15 +1621,15 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, ...@@ -1625,15 +1621,15 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
return true; return true;
} }
SvNumberformat *pEntry = NULL; boost::scoped_ptr<SvNumberformat> pEntry;
sal_Int32 nCheckPos = -1; sal_Int32 nCheckPos = -1;
OUString sTmpString; OUString sTmpString;
if ( bEnglish ) if ( bEnglish )
{ {
sTmpString = sFormatString; sTmpString = sFormatString;
pEntry = new SvNumberformat( sTmpString, pFormatScanner, pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
pStringScanner, nCheckPos, eLnge ); pStringScanner, nCheckPos, eLnge ));
} }
else else
{ {
...@@ -1645,8 +1641,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, ...@@ -1645,8 +1641,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
LanguageType eFormatLang = LANGUAGE_ENGLISH_US; LanguageType eFormatLang = LANGUAGE_ENGLISH_US;
pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge ); pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge );
sTmpString = sFormatString; sTmpString = sFormatString;
pEntry = new SvNumberformat( sTmpString, pFormatScanner, pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
pStringScanner, nCheckPos, eFormatLang ); pStringScanner, nCheckPos, eFormatLang ));
pFormatScanner->SetConvertMode( false ); pFormatScanner->SetConvertMode( false );
ChangeIntl( eLnge ); ChangeIntl( eLnge );
...@@ -1656,10 +1652,9 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, ...@@ -1656,10 +1652,9 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
pEntry->GetFormatstring() ) ) pEntry->GetFormatstring() ) )
{ {
// other Format // other Format
delete pEntry;
sTmpString = sFormatString; sTmpString = sFormatString;
pEntry = new SvNumberformat( sTmpString, pFormatScanner, pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
pStringScanner, nCheckPos, eLnge ); pStringScanner, nCheckPos, eLnge ));
} }
else else
{ {
...@@ -1669,20 +1664,18 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, ...@@ -1669,20 +1664,18 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
eFormatLang = eLnge; eFormatLang = eLnge;
pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US ); pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US );
sTmpString = sFormatString; sTmpString = sFormatString;
SvNumberformat* pEntry2 = new SvNumberformat( sTmpString, pFormatScanner, boost::scoped_ptr<SvNumberformat> pEntry2(new SvNumberformat( sTmpString, pFormatScanner,
pStringScanner, nCheckPos2, eFormatLang ); pStringScanner, nCheckPos2, eFormatLang ));
pFormatScanner->SetConvertMode( false ); pFormatScanner->SetConvertMode( false );
ChangeIntl( eLnge ); ChangeIntl( eLnge );
if ( nCheckPos2 == 0 && !xTransliteration->isEqual( sFormatString, if ( nCheckPos2 == 0 && !xTransliteration->isEqual( sFormatString,
pEntry2->GetFormatstring() ) ) pEntry2->GetFormatstring() ) )
{ {
// other Format // other Format
delete pEntry;
sTmpString = sFormatString; sTmpString = sFormatString;
pEntry = new SvNumberformat( sTmpString, pFormatScanner, pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
pStringScanner, nCheckPos, eLnge ); pStringScanner, nCheckPos, eLnge ));
} }
delete pEntry2;
} }
} }
} }
...@@ -1691,10 +1684,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, ...@@ -1691,10 +1684,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
{ {
ImpGenerateCL( eLnge ); // create new standard formats if necessary ImpGenerateCL( eLnge ); // create new standard formats if necessary
pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor ); pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor );
delete pEntry;
return true; return true;
} }
delete pEntry;
return false; return false;
} }
...@@ -1717,11 +1708,11 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString, ...@@ -1717,11 +1708,11 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString,
eLnge = ActLnge; eLnge = ActLnge;
sal_Int32 nCheckPos = -1; sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString; OUString sTmpString = sFormatString;
SvNumberformat* p_Entry = new SvNumberformat( sTmpString, boost::scoped_ptr<SvNumberformat> p_Entry(new SvNumberformat( sTmpString,
pFormatScanner, pFormatScanner,
pStringScanner, pStringScanner,
nCheckPos, nCheckPos,
eLnge); eLnge));
if (nCheckPos == 0) // String ok if (nCheckPos == 0) // String ok
{ {
// May have to create standard formats for this locale. // May have to create standard formats for this locale.
...@@ -1746,12 +1737,10 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString, ...@@ -1746,12 +1737,10 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString,
sOutString = sPreviewString; sOutString = sPreviewString;
} }
} }
delete p_Entry;
return true; return true;
} }
else else
{ {
delete p_Entry;
return false; return false;
} }
} }
...@@ -1772,11 +1761,11 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString, ...@@ -1772,11 +1761,11 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString,
sal_uInt32 nRes; sal_uInt32 nRes;
sal_Int32 nCheckPos = -1; sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString; OUString sTmpString = sFormatString;
SvNumberformat* pEntry = new SvNumberformat(sTmpString, boost::scoped_ptr<SvNumberformat> pEntry(new SvNumberformat(sTmpString,
pFormatScanner, pFormatScanner,
pStringScanner, pStringScanner,
nCheckPos, nCheckPos,
eLnge); eLnge));
if (nCheckPos == 0) // String ok if (nCheckPos == 0) // String ok
{ {
sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary
...@@ -1787,7 +1776,6 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString, ...@@ -1787,7 +1776,6 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString,
{ {
nRes = NUMBERFORMAT_ENTRY_NOT_FOUND; nRes = NUMBERFORMAT_ENTRY_NOT_FOUND;
} }
delete pEntry;
return nRes; return nRes;
} }
...@@ -1988,8 +1976,8 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin ...@@ -1988,8 +1976,8 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin
eLnge = ActLnge; eLnge = ActLnge;
OUString aTmpStr( rFormatString ); OUString aTmpStr( rFormatString );
sal_Int32 nCheckPos = 0; sal_Int32 nCheckPos = 0;
SvNumberformat* pFormat = new SvNumberformat( aTmpStr, pFormatScanner, boost::scoped_ptr<SvNumberformat> pFormat(new SvNumberformat( aTmpStr, pFormatScanner,
pStringScanner, nCheckPos, eLnge ); pStringScanner, nCheckPos, eLnge ));
if ( nCheckPos == 0 ) if ( nCheckPos == 0 )
{ {
pFormat->GetFormatSpecialInfo( bThousand, IsRed, nPrecision, nAnzLeading ); pFormat->GetFormatSpecialInfo( bThousand, IsRed, nPrecision, nAnzLeading );
...@@ -2001,7 +1989,6 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin ...@@ -2001,7 +1989,6 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin
nPrecision = pFormatScanner->GetStandardPrec(); nPrecision = pFormatScanner->GetStandardPrec();
nAnzLeading = 0; nAnzLeading = 0;
} }
delete pFormat;
return nCheckPos; return nCheckPos;
} }
...@@ -3698,9 +3685,9 @@ void SvNumberFormatter::ImpInitCurrencyTable() ...@@ -3698,9 +3685,9 @@ void SvNumberFormatter::ImpInitCurrencyTable()
bInitializing = true; bInitializing = true;
LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType(); LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType();
LocaleDataWrapper* pLocaleData = new LocaleDataWrapper( boost::scoped_ptr<LocaleDataWrapper> pLocaleData(new LocaleDataWrapper(
::comphelper::getProcessComponentContext(), ::comphelper::getProcessComponentContext(),
SvtSysLocale().GetLanguageTag() ); SvtSysLocale().GetLanguageTag() ));
// get user configured currency // get user configured currency
OUString aConfiguredCurrencyAbbrev; OUString aConfiguredCurrencyAbbrev;
LanguageType eConfiguredCurrencyLanguage = LANGUAGE_SYSTEM; LanguageType eConfiguredCurrencyLanguage = LANGUAGE_SYSTEM;
...@@ -3835,7 +3822,7 @@ void SvNumberFormatter::ImpInitCurrencyTable() ...@@ -3835,7 +3822,7 @@ void SvNumberFormatter::ImpInitCurrencyTable()
LocaleDataWrapper::outputCheckMessage( LocaleDataWrapper::outputCheckMessage(
"SvNumberFormatter::ImpInitCurrencyTable: system currency not in I18N locale data."); "SvNumberFormatter::ImpInitCurrencyTable: system currency not in I18N locale data.");
} }
delete pLocaleData; pLocaleData.reset();
SvtSysLocaleOptions::SetCurrencyChangeLink( STATIC_LINK( NULL, SvNumberFormatter, CurrencyChangeLink ) ); SvtSysLocaleOptions::SetCurrencyChangeLink( STATIC_LINK( NULL, SvNumberFormatter, CurrencyChangeLink ) );
bInitializing = false; bInitializing = false;
bCurrencyTableInitialized = true; bCurrencyTableInitialized = true;
......
...@@ -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