diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-27 23:22:43 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-03-27 23:25:20 +0900 |
commit | ee6895c61f8c073288bbc73cae105c3c1c36b9f0 (patch) | |
tree | 1b85f3524f643e43ca0b26501838f40b51b96293 | |
parent | 3ffb8c2f58ae02ad201cd016f2331aed0523d46e (diff) |
Avoid possible resource leaks by boost::scoped_array
Change-Id: I3d26325995995f658cd6adcc80e0716cfcee7de0
-rw-r--r-- | comphelper/source/property/propagg.cxx | 36 | ||||
-rw-r--r-- | comphelper/source/property/propertysethelper.cxx | 20 |
2 files changed, 18 insertions, 38 deletions
diff --git a/comphelper/source/property/propagg.cxx b/comphelper/source/property/propagg.cxx index 545da88d45f7..18d91948dc54 100644 --- a/comphelper/source/property/propagg.cxx +++ b/comphelper/source/property/propagg.cxx @@ -30,6 +30,7 @@ #include <algorithm> #include <set> +#include <boost/scoped_array.hpp> namespace comphelper @@ -517,9 +518,9 @@ void SAL_CALL OPropertySetAggregationHelper::propertiesChange(const ::com::sun: } else { - sal_Int32* pHandles = new sal_Int32[nLen]; - ::com::sun::star::uno::Any* pNewValues = new ::com::sun::star::uno::Any[nLen]; - ::com::sun::star::uno::Any* pOldValues = new ::com::sun::star::uno::Any[nLen]; + boost::scoped_array<sal_Int32> pHandles(new sal_Int32[nLen]); + boost::scoped_array< ::com::sun::star::uno::Any> pNewValues(new ::com::sun::star::uno::Any[nLen]); + boost::scoped_array< ::com::sun::star::uno::Any> pOldValues(new ::com::sun::star::uno::Any[nLen]); const ::com::sun::star::beans::PropertyChangeEvent* pEvents = _rEvents.getConstArray(); sal_Int32 nDest = 0; @@ -536,11 +537,7 @@ void SAL_CALL OPropertySetAggregationHelper::propertiesChange(const ::com::sun: } if (nDest) - fire(pHandles, pNewValues, pOldValues, nDest, sal_False); - - delete[] pHandles; - delete[] pNewValues; - delete[] pOldValues; + fire(pHandles.get(), pNewValues.get(), pOldValues.get(), nDest, sal_False); } } @@ -775,9 +772,6 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( else { const ::com::sun::star::uno::Any* pValues = _rValues.getConstArray(); - ::com::sun::star::uno::Any* pConvertedValues = NULL; - ::com::sun::star::uno::Any* pOldValues = NULL; - sal_Int32* pHandles = NULL; try { @@ -815,18 +809,17 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( // reset, needed below pDelValues = DelValues.getArray(); - pHandles = new sal_Int32[ nLen - nAggCount ]; + boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ nLen - nAggCount ]); // get the map table cppu::IPropertyArrayHelper& rPH2 = getInfoHelper(); // fill the handle array - sal_Int32 nHitCount = rPH2.fillHandles( pHandles, DelPropertyNames ); + sal_Int32 nHitCount = rPH2.fillHandles( pHandles.get(), DelPropertyNames ); if (nHitCount != 0) { - - pConvertedValues = new ::com::sun::star::uno::Any[ nHitCount ]; - pOldValues = new ::com::sun::star::uno::Any[ nHitCount ]; + boost::scoped_array< ::com::sun::star::uno::Any> pConvertedValues(new ::com::sun::star::uno::Any[ nHitCount ]); + boost::scoped_array< ::com::sun::star::uno::Any> pOldValues(new ::com::sun::star::uno::Any[ nHitCount ]); nHitCount = 0; sal_Int32 i; @@ -855,7 +848,7 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( } // fire vetoable events - fire( pHandles, pConvertedValues, pOldValues, nHitCount, sal_True ); + fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, sal_True ); // setting the agg Properties m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); @@ -873,7 +866,7 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( } // fire change events - fire( pHandles, pConvertedValues, pOldValues, nHitCount, sal_False ); + fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, sal_False ); } else m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); @@ -881,15 +874,8 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( } catch(::com::sun::star::uno::Exception&) { - delete [] pHandles; - delete [] pOldValues; - delete [] pConvertedValues; throw; } - - delete [] pHandles; - delete [] pOldValues; - delete [] pConvertedValues; } } } diff --git a/comphelper/source/property/propertysethelper.cxx b/comphelper/source/property/propertysethelper.cxx index f7e366c3206f..17fc443de0e7 100644 --- a/comphelper/source/property/propertysethelper.cxx +++ b/comphelper/source/property/propertysethelper.cxx @@ -20,7 +20,7 @@ #include "comphelper/propertysetinfo.hxx" #include "comphelper/propertysethelper.hxx" - +#include <boost/scoped_array.hpp> using namespace ::rtl; @@ -141,7 +141,7 @@ void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& if( nCount ) { - PropertyMapEntry const ** pEntries = new PropertyMapEntry const *[nCount+1]; + boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]); pEntries[nCount] = NULL; const OUString* pNames = aPropertyNames.getConstArray(); @@ -154,9 +154,7 @@ void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& } if( !bUnknown ) - _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() ); - - delete[] pEntries; + _setPropertyValues( (const PropertyMapEntry**)pEntries.get(), aValues.getConstArray() ); if( bUnknown ) throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) ); @@ -170,7 +168,7 @@ Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< O Sequence< Any > aValues; if( nCount ) { - PropertyMapEntry const ** pEntries = new PropertyMapEntry const *[nCount+1]; + boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]); pEntries[nCount] = NULL; const OUString* pNames = aPropertyNames.getConstArray(); @@ -185,11 +183,9 @@ Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< O if( !bUnknown ) { aValues.realloc(nCount); - _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() ); + _getPropertyValues( (const PropertyMapEntry**)pEntries.get(), aValues.getArray() ); } - delete[] pEntries; - if( bUnknown ) throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) ); } @@ -241,7 +237,7 @@ Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const S bool bUnknown = false; - PropertyMapEntry const ** pEntries = new PropertyMapEntry const *[nCount+1]; + boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]); sal_Int32 n; for( n = 0; !bUnknown && (n < nCount); n++, pNames++ ) @@ -253,9 +249,7 @@ Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const S pEntries[nCount] = NULL; if( !bUnknown ) - _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() ); - - delete[] pEntries; + _getPropertyStates( (const PropertyMapEntry**)pEntries.get(), aStates.getArray() ); if( bUnknown ) throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) ); |