diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-07-11 14:23:50 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-07-12 07:57:32 +0900 |
commit | ef9449cd04748320ee45242feb53805eef07d44c (patch) | |
tree | c8e8d0fe9021d00b9959ea91d1e60a453254e5a7 /cppuhelper | |
parent | 18258eb811d1b8ad10810925952b8e32228128c5 (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I5e302cf7ac784e1413c0539d0c967a3523f04ba0
Diffstat (limited to 'cppuhelper')
-rw-r--r-- | cppuhelper/source/component_context.cxx | 8 | ||||
-rw-r--r-- | cppuhelper/source/interfacecontainer.cxx | 13 | ||||
-rw-r--r-- | cppuhelper/source/propshlp.cxx | 51 |
3 files changed, 22 insertions, 50 deletions
diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx index dc8944af5b79..16642e9133fb 100644 --- a/cppuhelper/source/component_context.cxx +++ b/cppuhelper/source/component_context.cxx @@ -54,6 +54,8 @@ #include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/uno/RuntimeException.hpp> +#include <boost/scoped_array.hpp> + #define SMGR_SINGLETON "/singletons/com.sun.star.lang.theServiceManager" #define TDMGR_SINGLETON "/singletons/com.sun.star.reflection.theTypeDescriptionManager" #define AC_SINGLETON "/singletons/com.sun.star.security.theAccessController" @@ -844,7 +846,7 @@ Reference< XComponentContext > SAL_CALL createComponentContext( uno::Mapping curr2source(curr_env, source_env); uno::Mapping source2curr(source_env, curr_env); - ContextEntry_Init * mapped_entries = new ContextEntry_Init[nEntries]; + boost::scoped_array<ContextEntry_Init> mapped_entries(new ContextEntry_Init[nEntries]); for (sal_Int32 nPos = 0; nPos < nEntries; ++ nPos) { mapped_entries[nPos].bLateInitService = pEntries[nPos].bLateInitService; @@ -858,8 +860,8 @@ Reference< XComponentContext > SAL_CALL createComponentContext( void * mapped_delegate = curr2source.mapInterface(xDelegate.get(), ::getCppuType(&xDelegate)); XComponentContext * pXComponentContext = NULL; - source_env.invoke(s_createComponentContext_v, mapped_entries, nEntries, mapped_delegate, &pXComponentContext, &source2curr); - delete[] mapped_entries; + source_env.invoke(s_createComponentContext_v, mapped_entries.get(), nEntries, mapped_delegate, &pXComponentContext, &source2curr); + mapped_entries.reset(); return Reference<XComponentContext>(pXComponentContext, SAL_NO_ACQUIRE); } diff --git a/cppuhelper/source/interfacecontainer.cxx b/cppuhelper/source/interfacecontainer.cxx index 22f090b08d23..0a0e251e689a 100644 --- a/cppuhelper/source/interfacecontainer.cxx +++ b/cppuhelper/source/interfacecontainer.cxx @@ -25,6 +25,7 @@ #include <osl/diagnose.h> #include <osl/mutex.hxx> +#include <boost/scoped_array.hpp> #include <boost/unordered_map.hpp> #include <com/sun/star/lang/XEventListener.hpp> @@ -455,7 +456,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelper::removeInterface( void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rEvt ) { t_type2ptr::size_type nSize = 0; - OInterfaceContainerHelper ** ppListenerContainers = NULL; + boost::scoped_array<OInterfaceContainerHelper *> ppListenerContainers; { ::osl::MutexGuard aGuard( rMutex ); t_type2ptr * pMap = (t_type2ptr *)m_pMap; @@ -463,7 +464,7 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE if( nSize ) { typedef OInterfaceContainerHelper* ppp; - ppListenerContainers = new ppp[nSize]; + ppListenerContainers.reset(new ppp[nSize]); //ppListenerContainers = new (ListenerContainer*)[nSize]; t_type2ptr::iterator iter = pMap->begin(); @@ -485,8 +486,6 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE if( ppListenerContainers[i] ) ppListenerContainers[i]->disposeAndClear( rEvt ); } - - delete [] ppListenerContainers; } void OMultiTypeInterfaceContainerHelper::clear() @@ -631,7 +630,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelperInt32::removeInterface( void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject & rEvt ) { t_long2ptr::size_type nSize = 0; - OInterfaceContainerHelper ** ppListenerContainers = NULL; + boost::scoped_array<OInterfaceContainerHelper *> ppListenerContainers; { ::osl::MutexGuard aGuard( rMutex ); if (!m_pMap) @@ -642,7 +641,7 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject if( nSize ) { typedef OInterfaceContainerHelper* ppp; - ppListenerContainers = new ppp[nSize]; + ppListenerContainers.reset(new ppp[nSize]); t_long2ptr::iterator iter = pMap->begin(); t_long2ptr::iterator end = pMap->end(); @@ -663,8 +662,6 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject if( ppListenerContainers[i] ) ppListenerContainers[i]->disposeAndClear( rEvt ); } - - delete [] ppListenerContainers; } void OMultiTypeInterfaceContainerHelperInt32::clear() 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 ) |