[Libreoffice-commits] core.git: svl/source
Takeshi Abe
tabe at fixedpoint.jp
Wed Jul 9 14:43:54 PDT 2014
svl/source/items/itemprop.cxx | 9 ++---
svl/source/items/poolio.cxx | 4 +-
svl/source/numbers/zforlist.cxx | 65 ++++++++++++++++------------------------
svl/source/numbers/zformat.cxx | 7 ++--
4 files changed, 36 insertions(+), 49 deletions(-)
New commits:
commit 4468ab0e0c0ecb50de68d2ecce327756a50eb0ae
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Thu Jul 10 00:05:35 2014 +0900
Avoid possible memory leaks in case of exceptions
Change-Id: I1dd003bc984a11d6d71c92aae44accc9d358db0c
diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx
index 41f1a04..3ba833f 100644
--- a/svl/source/items/itemprop.cxx
+++ b/svl/source/items/itemprop.cxx
@@ -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;
}
}
diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx
index ac481ba..08267a9 100644
--- a/svl/source/items/poolio.cxx
+++ b/svl/source/items/poolio.cxx
@@ -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
}
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 020d845..4c0f6bd 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -45,6 +45,7 @@
#include <math.h>
#include <limits>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -685,7 +686,7 @@ void SvNumberFormatter::DeleteEntry(sal_uInt32 nKey)
bool SvNumberFormatter::Load( SvStream& rStream )
{
LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType();
- SvNumberFormatter* pConverter = NULL;
+ boost::scoped_ptr<SvNumberFormatter> pConverter;
ImpSvNumMultipleReadHeader aHdr( rStream );
sal_uInt16 nVersion;
@@ -725,7 +726,7 @@ bool SvNumberFormatter::Load( SvStream& rStream )
// different SYSTEM locale
if ( !pConverter )
{
- pConverter = new SvNumberFormatter( m_xContext, eSysLang );
+ pConverter.reset(new SvNumberFormatter( m_xContext, eSysLang ));
}
pEntry->ConvertLanguage( *pConverter, eSaveSysLang, eLoadSysLang, true );
}
@@ -763,10 +764,7 @@ bool SvNumberFormatter::Load( SvStream& rStream )
aHdr.EndEntry();
}
- if ( pConverter )
- {
- delete pConverter;
- }
+ pConverter.reset();
// generate additional i18n standard formats for all used locales
LanguageType eOldLanguage = ActLnge;
@@ -1562,11 +1560,11 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString,
eLnge = ActLnge;
sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString;
- SvNumberformat* p_Entry = new SvNumberformat(sTmpString,
+ boost::scoped_ptr<SvNumberformat> p_Entry(new SvNumberformat(sTmpString,
pFormatScanner,
pStringScanner,
nCheckPos,
- eLnge);
+ eLnge));
if (nCheckPos == 0) // String ok
{
sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary
@@ -1587,12 +1585,10 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString,
p_Entry->SetStarFormatSupport( false );
}
}
- delete p_Entry;
return true;
}
else
{
- delete p_Entry;
return false;
}
}
@@ -1625,15 +1621,15 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
return true;
}
- SvNumberformat *pEntry = NULL;
+ boost::scoped_ptr<SvNumberformat> pEntry;
sal_Int32 nCheckPos = -1;
OUString sTmpString;
if ( bEnglish )
{
sTmpString = sFormatString;
- pEntry = new SvNumberformat( sTmpString, pFormatScanner,
- pStringScanner, nCheckPos, eLnge );
+ pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
+ pStringScanner, nCheckPos, eLnge ));
}
else
{
@@ -1645,8 +1641,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
LanguageType eFormatLang = LANGUAGE_ENGLISH_US;
pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge );
sTmpString = sFormatString;
- pEntry = new SvNumberformat( sTmpString, pFormatScanner,
- pStringScanner, nCheckPos, eFormatLang );
+ pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
+ pStringScanner, nCheckPos, eFormatLang ));
pFormatScanner->SetConvertMode( false );
ChangeIntl( eLnge );
@@ -1656,10 +1652,9 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
pEntry->GetFormatstring() ) )
{
// other Format
- delete pEntry;
sTmpString = sFormatString;
- pEntry = new SvNumberformat( sTmpString, pFormatScanner,
- pStringScanner, nCheckPos, eLnge );
+ pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
+ pStringScanner, nCheckPos, eLnge ));
}
else
{
@@ -1669,20 +1664,18 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
eFormatLang = eLnge;
pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US );
sTmpString = sFormatString;
- SvNumberformat* pEntry2 = new SvNumberformat( sTmpString, pFormatScanner,
- pStringScanner, nCheckPos2, eFormatLang );
+ boost::scoped_ptr<SvNumberformat> pEntry2(new SvNumberformat( sTmpString, pFormatScanner,
+ pStringScanner, nCheckPos2, eFormatLang ));
pFormatScanner->SetConvertMode( false );
ChangeIntl( eLnge );
if ( nCheckPos2 == 0 && !xTransliteration->isEqual( sFormatString,
pEntry2->GetFormatstring() ) )
{
// other Format
- delete pEntry;
sTmpString = sFormatString;
- pEntry = new SvNumberformat( sTmpString, pFormatScanner,
- pStringScanner, nCheckPos, eLnge );
+ pEntry.reset(new SvNumberformat( sTmpString, pFormatScanner,
+ pStringScanner, nCheckPos, eLnge ));
}
- delete pEntry2;
}
}
}
@@ -1691,10 +1684,8 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString,
{
ImpGenerateCL( eLnge ); // create new standard formats if necessary
pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor );
- delete pEntry;
return true;
}
- delete pEntry;
return false;
}
@@ -1717,11 +1708,11 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString,
eLnge = ActLnge;
sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString;
- SvNumberformat* p_Entry = new SvNumberformat( sTmpString,
+ boost::scoped_ptr<SvNumberformat> p_Entry(new SvNumberformat( sTmpString,
pFormatScanner,
pStringScanner,
nCheckPos,
- eLnge);
+ eLnge));
if (nCheckPos == 0) // String ok
{
// May have to create standard formats for this locale.
@@ -1746,12 +1737,10 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString,
sOutString = sPreviewString;
}
}
- delete p_Entry;
return true;
}
else
{
- delete p_Entry;
return false;
}
}
@@ -1772,11 +1761,11 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString,
sal_uInt32 nRes;
sal_Int32 nCheckPos = -1;
OUString sTmpString = sFormatString;
- SvNumberformat* pEntry = new SvNumberformat(sTmpString,
+ boost::scoped_ptr<SvNumberformat> pEntry(new SvNumberformat(sTmpString,
pFormatScanner,
pStringScanner,
nCheckPos,
- eLnge);
+ eLnge));
if (nCheckPos == 0) // String ok
{
sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary
@@ -1787,7 +1776,6 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString,
{
nRes = NUMBERFORMAT_ENTRY_NOT_FOUND;
}
- delete pEntry;
return nRes;
}
@@ -1988,8 +1976,8 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin
eLnge = ActLnge;
OUString aTmpStr( rFormatString );
sal_Int32 nCheckPos = 0;
- SvNumberformat* pFormat = new SvNumberformat( aTmpStr, pFormatScanner,
- pStringScanner, nCheckPos, eLnge );
+ boost::scoped_ptr<SvNumberformat> pFormat(new SvNumberformat( aTmpStr, pFormatScanner,
+ pStringScanner, nCheckPos, eLnge ));
if ( nCheckPos == 0 )
{
pFormat->GetFormatSpecialInfo( bThousand, IsRed, nPrecision, nAnzLeading );
@@ -2001,7 +1989,6 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin
nPrecision = pFormatScanner->GetStandardPrec();
nAnzLeading = 0;
}
- delete pFormat;
return nCheckPos;
}
@@ -3698,9 +3685,9 @@ void SvNumberFormatter::ImpInitCurrencyTable()
bInitializing = true;
LanguageType eSysLang = SvtSysLocale().GetLanguageTag().getLanguageType();
- LocaleDataWrapper* pLocaleData = new LocaleDataWrapper(
+ boost::scoped_ptr<LocaleDataWrapper> pLocaleData(new LocaleDataWrapper(
::comphelper::getProcessComponentContext(),
- SvtSysLocale().GetLanguageTag() );
+ SvtSysLocale().GetLanguageTag() ));
// get user configured currency
OUString aConfiguredCurrencyAbbrev;
LanguageType eConfiguredCurrencyLanguage = LANGUAGE_SYSTEM;
@@ -3835,7 +3822,7 @@ void SvNumberFormatter::ImpInitCurrencyTable()
LocaleDataWrapper::outputCheckMessage(
"SvNumberFormatter::ImpInitCurrencyTable: system currency not in I18N locale data.");
}
- delete pLocaleData;
+ pLocaleData.reset();
SvtSysLocaleOptions::SetCurrencyChangeLink( STATIC_LINK( NULL, SvNumberFormatter, CurrencyChangeLink ) );
bInitializing = false;
bCurrencyTableInitialized = true;
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index ef94a23..5815cac 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -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;
More information about the Libreoffice-commits
mailing list