Kaydet (Commit) ef9449cd authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: I5e302cf7ac784e1413c0539d0c967a3523f04ba0
üst 18258eb8
...@@ -54,6 +54,8 @@ ...@@ -54,6 +54,8 @@
#include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/uno/DeploymentException.hpp>
#include <com/sun/star/uno/RuntimeException.hpp> #include <com/sun/star/uno/RuntimeException.hpp>
#include <boost/scoped_array.hpp>
#define SMGR_SINGLETON "/singletons/com.sun.star.lang.theServiceManager" #define SMGR_SINGLETON "/singletons/com.sun.star.lang.theServiceManager"
#define TDMGR_SINGLETON "/singletons/com.sun.star.reflection.theTypeDescriptionManager" #define TDMGR_SINGLETON "/singletons/com.sun.star.reflection.theTypeDescriptionManager"
#define AC_SINGLETON "/singletons/com.sun.star.security.theAccessController" #define AC_SINGLETON "/singletons/com.sun.star.security.theAccessController"
...@@ -844,7 +846,7 @@ Reference< XComponentContext > SAL_CALL createComponentContext( ...@@ -844,7 +846,7 @@ Reference< XComponentContext > SAL_CALL createComponentContext(
uno::Mapping curr2source(curr_env, source_env); uno::Mapping curr2source(curr_env, source_env);
uno::Mapping source2curr(source_env, curr_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) for (sal_Int32 nPos = 0; nPos < nEntries; ++ nPos)
{ {
mapped_entries[nPos].bLateInitService = pEntries[nPos].bLateInitService; mapped_entries[nPos].bLateInitService = pEntries[nPos].bLateInitService;
...@@ -858,8 +860,8 @@ Reference< XComponentContext > SAL_CALL createComponentContext( ...@@ -858,8 +860,8 @@ Reference< XComponentContext > SAL_CALL createComponentContext(
void * mapped_delegate = curr2source.mapInterface(xDelegate.get(), ::getCppuType(&xDelegate)); void * mapped_delegate = curr2source.mapInterface(xDelegate.get(), ::getCppuType(&xDelegate));
XComponentContext * pXComponentContext = NULL; XComponentContext * pXComponentContext = NULL;
source_env.invoke(s_createComponentContext_v, mapped_entries, nEntries, mapped_delegate, &pXComponentContext, &source2curr); source_env.invoke(s_createComponentContext_v, mapped_entries.get(), nEntries, mapped_delegate, &pXComponentContext, &source2curr);
delete[] mapped_entries; mapped_entries.reset();
return Reference<XComponentContext>(pXComponentContext, SAL_NO_ACQUIRE); return Reference<XComponentContext>(pXComponentContext, SAL_NO_ACQUIRE);
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <boost/scoped_array.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XEventListener.hpp>
...@@ -455,7 +456,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelper::removeInterface( ...@@ -455,7 +456,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelper::removeInterface(
void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rEvt ) void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rEvt )
{ {
t_type2ptr::size_type nSize = 0; t_type2ptr::size_type nSize = 0;
OInterfaceContainerHelper ** ppListenerContainers = NULL; boost::scoped_array<OInterfaceContainerHelper *> ppListenerContainers;
{ {
::osl::MutexGuard aGuard( rMutex ); ::osl::MutexGuard aGuard( rMutex );
t_type2ptr * pMap = (t_type2ptr *)m_pMap; t_type2ptr * pMap = (t_type2ptr *)m_pMap;
...@@ -463,7 +464,7 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE ...@@ -463,7 +464,7 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE
if( nSize ) if( nSize )
{ {
typedef OInterfaceContainerHelper* ppp; typedef OInterfaceContainerHelper* ppp;
ppListenerContainers = new ppp[nSize]; ppListenerContainers.reset(new ppp[nSize]);
//ppListenerContainers = new (ListenerContainer*)[nSize]; //ppListenerContainers = new (ListenerContainer*)[nSize];
t_type2ptr::iterator iter = pMap->begin(); t_type2ptr::iterator iter = pMap->begin();
...@@ -485,8 +486,6 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE ...@@ -485,8 +486,6 @@ void OMultiTypeInterfaceContainerHelper::disposeAndClear( const EventObject & rE
if( ppListenerContainers[i] ) if( ppListenerContainers[i] )
ppListenerContainers[i]->disposeAndClear( rEvt ); ppListenerContainers[i]->disposeAndClear( rEvt );
} }
delete [] ppListenerContainers;
} }
void OMultiTypeInterfaceContainerHelper::clear() void OMultiTypeInterfaceContainerHelper::clear()
...@@ -631,7 +630,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelperInt32::removeInterface( ...@@ -631,7 +630,7 @@ sal_Int32 OMultiTypeInterfaceContainerHelperInt32::removeInterface(
void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject & rEvt ) void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject & rEvt )
{ {
t_long2ptr::size_type nSize = 0; t_long2ptr::size_type nSize = 0;
OInterfaceContainerHelper ** ppListenerContainers = NULL; boost::scoped_array<OInterfaceContainerHelper *> ppListenerContainers;
{ {
::osl::MutexGuard aGuard( rMutex ); ::osl::MutexGuard aGuard( rMutex );
if (!m_pMap) if (!m_pMap)
...@@ -642,7 +641,7 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject ...@@ -642,7 +641,7 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject
if( nSize ) if( nSize )
{ {
typedef OInterfaceContainerHelper* ppp; typedef OInterfaceContainerHelper* ppp;
ppListenerContainers = new ppp[nSize]; ppListenerContainers.reset(new ppp[nSize]);
t_long2ptr::iterator iter = pMap->begin(); t_long2ptr::iterator iter = pMap->begin();
t_long2ptr::iterator end = pMap->end(); t_long2ptr::iterator end = pMap->end();
...@@ -663,8 +662,6 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject ...@@ -663,8 +662,6 @@ void OMultiTypeInterfaceContainerHelperInt32::disposeAndClear( const EventObject
if( ppListenerContainers[i] ) if( ppListenerContainers[i] )
ppListenerContainers[i]->disposeAndClear( rEvt ); ppListenerContainers[i]->disposeAndClear( rEvt );
} }
delete [] ppListenerContainers;
} }
void OMultiTypeInterfaceContainerHelperInt32::clear() void OMultiTypeInterfaceContainerHelperInt32::clear()
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/DisposedException.hpp>
#include <boost/scoped_array.hpp>
using namespace osl; using namespace osl;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
...@@ -839,16 +839,11 @@ void OPropertySetHelper::setFastPropertyValues( ...@@ -839,16 +839,11 @@ void OPropertySetHelper::setFastPropertyValues(
OSL_ENSURE( !rBHelper.bInDispose, "do not getFastPropertyValue in the dispose call" ); OSL_ENSURE( !rBHelper.bInDispose, "do not getFastPropertyValue in the dispose call" );
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" ); OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
Any * pConvertedValues = NULL;
Any * pOldValues = NULL;
try
{
// get the map table // get the map table
IPropertyArrayHelper & rPH = getInfoHelper(); IPropertyArrayHelper & rPH = getInfoHelper();
pConvertedValues = new Any[ nHitCount ]; boost::scoped_array<Any> pConvertedValues(new Any[ nHitCount ]);
pOldValues = new Any[ nHitCount ]; boost::scoped_array<Any> pOldValues(new Any[ nHitCount ]);
sal_Int32 n = 0; sal_Int32 n = 0;
sal_Int32 i; sal_Int32 i;
...@@ -878,7 +873,7 @@ void OPropertySetHelper::setFastPropertyValues( ...@@ -878,7 +873,7 @@ void OPropertySetHelper::setFastPropertyValues(
} }
// fire vetoable events // 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. // must lock the mutex outside the loop.
...@@ -893,16 +888,7 @@ void OPropertySetHelper::setFastPropertyValues( ...@@ -893,16 +888,7 @@ void OPropertySetHelper::setFastPropertyValues(
} }
// fire change events // fire change events
impl_fireAll( pHandles, pConvertedValues, pOldValues, n ); impl_fireAll( pHandles, pConvertedValues.get(), pOldValues.get(), n );
}
catch( ... )
{
delete [] pOldValues;
delete [] pConvertedValues;
throw;
}
delete [] pOldValues;
delete [] pConvertedValues;
} }
// XMultiPropertySet // XMultiPropertySet
...@@ -915,24 +901,14 @@ void OPropertySetHelper::setPropertyValues( ...@@ -915,24 +901,14 @@ void OPropertySetHelper::setPropertyValues(
const Sequence<Any>& rValues ) 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) 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(); sal_Int32 nSeqLen = rPropertyNames.getLength();
pHandles = new sal_Int32[ nSeqLen ]; boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ nSeqLen ]);
// get the map table // get the map table
IPropertyArrayHelper & rPH = getInfoHelper(); IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array // fill the handle array
sal_Int32 nHitCount = rPH.fillHandles( pHandles, rPropertyNames ); sal_Int32 nHitCount = rPH.fillHandles( pHandles.get(), rPropertyNames );
if( nHitCount != 0 ) if( nHitCount != 0 )
setFastPropertyValues( nSeqLen, pHandles, rValues.getConstArray(), nHitCount ); setFastPropertyValues( nSeqLen, pHandles.get(), rValues.getConstArray(), nHitCount );
}
catch( ... )
{
delete [] pHandles;
throw;
}
delete [] pHandles;
} }
// XMultiPropertySet // XMultiPropertySet
...@@ -940,13 +916,13 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r ...@@ -940,13 +916,13 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r
throw(::com::sun::star::uno::RuntimeException, std::exception) throw(::com::sun::star::uno::RuntimeException, std::exception)
{ {
sal_Int32 nSeqLen = rPropertyNames.getLength(); 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 ); Sequence< Any > aValues( nSeqLen );
// get the map table // get the map table
IPropertyArrayHelper & rPH = getInfoHelper(); IPropertyArrayHelper & rPH = getInfoHelper();
// fill the handle array // fill the handle array
rPH.fillHandles( pHandles, rPropertyNames ); rPH.fillHandles( pHandles.get(), rPropertyNames );
Any * pValues = aValues.getArray(); Any * pValues = aValues.getArray();
...@@ -955,7 +931,6 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r ...@@ -955,7 +931,6 @@ Sequence<Any> OPropertySetHelper::getPropertyValues( const Sequence<OUString>& r
for( sal_Int32 i = 0; i < nSeqLen; i++ ) for( sal_Int32 i = 0; i < nSeqLen; i++ )
getFastPropertyValue( pValues[i], pHandles[i] ); getFastPropertyValue( pValues[i], pHandles[i] );
delete [] pHandles;
return aValues; return aValues;
} }
...@@ -983,9 +958,9 @@ void OPropertySetHelper::firePropertiesChangeEvent( ...@@ -983,9 +958,9 @@ void OPropertySetHelper::firePropertiesChangeEvent(
throw(::com::sun::star::uno::RuntimeException, std::exception) throw(::com::sun::star::uno::RuntimeException, std::exception)
{ {
sal_Int32 nLen = rPropertyNames.getLength(); 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(); IPropertyArrayHelper & rPH = getInfoHelper();
rPH.fillHandles( pHandles, rPropertyNames ); rPH.fillHandles( pHandles.get(), rPropertyNames );
const OUString* pNames = rPropertyNames.getConstArray(); const OUString* pNames = rPropertyNames.getConstArray();
// get the count of matching properties // get the count of matching properties
...@@ -1019,8 +994,6 @@ void OPropertySetHelper::firePropertiesChangeEvent( ...@@ -1019,8 +994,6 @@ void OPropertySetHelper::firePropertiesChangeEvent(
} }
if( nFireLen ) if( nFireLen )
rListener->propertiesChange( aChanges ); rListener->propertiesChange( aChanges );
delete [] pHandles;
} }
void OPropertySetHelper2::enableChangeListenerNotification( sal_Bool bEnable ) void OPropertySetHelper2::enableChangeListenerNotification( sal_Bool bEnable )
......
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