summaryrefslogtreecommitdiff
path: root/cppuhelper/source/propshlp.cxx
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-07-11 14:23:50 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-07-12 07:57:32 +0900
commitef9449cd04748320ee45242feb53805eef07d44c (patch)
treec8e8d0fe9021d00b9959ea91d1e60a453254e5a7 /cppuhelper/source/propshlp.cxx
parent18258eb811d1b8ad10810925952b8e32228128c5 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: I5e302cf7ac784e1413c0539d0c967a3523f04ba0
Diffstat (limited to 'cppuhelper/source/propshlp.cxx')
-rw-r--r--cppuhelper/source/propshlp.cxx51
1 files changed, 12 insertions, 39 deletions
diff --git a/cppuhelper/source/propshlp.cxx b/cppuhelper/source/propshlp.cxx
index 903b222224b4..94500ba2def5 100644
--- a/cppuhelper/source/propshlp.cxx
+++ b/cppuhelper/source/propshlp.cxx
@@ -25,7 +25,7 @@
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
-
+#include <boost/scoped_array.hpp>
using namespace osl;
using namespace com::sun::star::uno;
@@ -839,16 +839,11 @@ void OPropertySetHelper::setFastPropertyValues(
OSL_ENSURE( !rBHelper.bInDispose, "do not getFastPropertyValue in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
- Any * pConvertedValues = NULL;
- Any * pOldValues = NULL;
-
- try
- {
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
- pConvertedValues = new Any[ nHitCount ];
- pOldValues = new Any[ nHitCount ];
+ boost::scoped_array<Any> pConvertedValues(new Any[ nHitCount ]);
+ boost::scoped_array<Any> pOldValues(new Any[ nHitCount ]);
sal_Int32 n = 0;
sal_Int32 i;
@@ -878,7 +873,7 @@ void OPropertySetHelper::setFastPropertyValues(
}
// fire vetoable events
- fire( pHandles, pConvertedValues, pOldValues, n, sal_True );
+ fire( pHandles, pConvertedValues.get(), pOldValues.get(), n, sal_True );
{
// must lock the mutex outside the loop.
@@ -893,16 +888,7 @@ void OPropertySetHelper::setFastPropertyValues(
}
// fire change events
- impl_fireAll( pHandles, pConvertedValues, pOldValues, n );
- }
- catch( ... )
- {
- delete [] pOldValues;
- delete [] pConvertedValues;
- throw;
- }
- delete [] pOldValues;
- delete [] pConvertedValues;
+ impl_fireAll( pHandles, pConvertedValues.get(), pOldValues.get(), n );
}
// XMultiPropertySet
@@ -915,24 +901,14 @@ void OPropertySetHelper::setPropertyValues(
const Sequence<Any>& rValues )
throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
{
- sal_Int32 * pHandles = NULL;
- try
- {
sal_Int32 nSeqLen = rPropertyNames.getLength();
- pHandles = new sal_Int32[ nSeqLen ];
+ boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ nSeqLen ]);
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array
- sal_Int32 nHitCount = rPH.fillHandles( pHandles, rPropertyNames );
+ sal_Int32 nHitCount = rPH.fillHandles( pHandles.get(), rPropertyNames );
if( nHitCount != 0 )
- setFastPropertyValues( nSeqLen, pHandles, rValues.getConstArray(), nHitCount );
- }
- catch( ... )
- {
- delete [] pHandles;
- throw;
- }
- delete [] pHandles;
+ setFastPropertyValues( nSeqLen, pHandles.get(), rValues.getConstArray(), nHitCount );
}
// XMultiPropertySet
@@ -940,13 +916,13 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r
throw(::com::sun::star::uno::RuntimeException, std::exception)
{
sal_Int32 nSeqLen = rPropertyNames.getLength();
- sal_Int32 * pHandles = new sal_Int32[ nSeqLen ];
+ boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ nSeqLen ]);
Sequence< Any > aValues( nSeqLen );
// get the map table
IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array
- rPH.fillHandles( pHandles, rPropertyNames );
+ rPH.fillHandles( pHandles.get(), rPropertyNames );
Any * pValues = aValues.getArray();
@@ -955,7 +931,6 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r
for( sal_Int32 i = 0; i < nSeqLen; i++ )
getFastPropertyValue( pValues[i], pHandles[i] );
- delete [] pHandles;
return aValues;
}
@@ -983,9 +958,9 @@ void OPropertySetHelper::firePropertiesChangeEvent(
throw(::com::sun::star::uno::RuntimeException, std::exception)
{
sal_Int32 nLen = rPropertyNames.getLength();
- sal_Int32 * pHandles = new sal_Int32[nLen];
+ boost::scoped_array<sal_Int32> pHandles(new sal_Int32[nLen]);
IPropertyArrayHelper & rPH = getInfoHelper();
- rPH.fillHandles( pHandles, rPropertyNames );
+ rPH.fillHandles( pHandles.get(), rPropertyNames );
const OUString* pNames = rPropertyNames.getConstArray();
// get the count of matching properties
@@ -1019,8 +994,6 @@ void OPropertySetHelper::firePropertiesChangeEvent(
}
if( nFireLen )
rListener->propertiesChange( aChanges );
-
- delete [] pHandles;
}
void OPropertySetHelper2::enableChangeListenerNotification( sal_Bool bEnable )