diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-10 14:14:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-10 15:14:48 +0200 |
commit | 0afb2b63b38dff138e66f4ac8afed60911cb6aad (patch) | |
tree | 6f0d5e837600a460a57fce6383bc4eef10cdfc7a /basic/source/classes | |
parent | b3541dea4889b9d0039554f87bd16e55189cf8b1 (diff) |
fix some leaks in basic
Change-Id: I52c10cdbe9661974c908ee052336c779a40de402
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115323
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic/source/classes')
-rw-r--r-- | basic/source/classes/image.cxx | 4 | ||||
-rw-r--r-- | basic/source/classes/sb.cxx | 48 | ||||
-rw-r--r-- | basic/source/classes/sbunoobj.cxx | 10 | ||||
-rw-r--r-- | basic/source/classes/sbxmod.cxx | 38 |
4 files changed, 48 insertions, 52 deletions
diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx index ea93303e41c8..52aee6636c79 100644 --- a/basic/source/classes/image.cxx +++ b/basic/source/classes/image.cxx @@ -308,8 +308,8 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) SbxObject* pNestedTypeObj = static_cast< SbxObject* >( rTypes->Find( aNestedTypeName, SbxClassType::Object ) ); if (pNestedTypeObj) { - SbxObject* pCloneObj = cloneTypeObjectImpl( *pNestedTypeObj ); - pTypeElem->PutObject( pCloneObj ); + SbxObjectRef pCloneObj = cloneTypeObjectImpl( *pNestedTypeObj ); + pTypeElem->PutObject( pCloneObj.get() ); } } else diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 10d7f4281271..74eacdb504c6 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -410,7 +410,7 @@ const SFX_VB_ErrorItem SFX_VB_ErrorTab[] = // the Module-relationship. But it works only when a module is loaded. // Can cause troubles with separately loaded properties! -SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) +SbxBaseRef SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) { if( nCreator == SBXCR_SBX ) { @@ -433,7 +433,7 @@ SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) return nullptr; } -SbxObject* SbiFactory::CreateObject( const OUString& rClass ) +SbxObjectRef SbiFactory::CreateObject( const OUString& rClass ) { if( rClass.equalsIgnoreAsciiCase( "StarBASIC" ) ) { @@ -464,28 +464,28 @@ SbxObject* SbiFactory::CreateObject( const OUString& rClass ) } -SbxBase* SbOLEFactory::Create( sal_uInt16, sal_uInt32 ) +SbxBaseRef SbOLEFactory::Create( sal_uInt16, sal_uInt32 ) { // Not supported return nullptr; } -SbxObject* SbOLEFactory::CreateObject( const OUString& rClassName ) +SbxObjectRef SbOLEFactory::CreateObject( const OUString& rClassName ) { - SbxObject* pRet = createOLEObject_Impl( rClassName ); + SbxObjectRef pRet = createOLEObject_Impl( rClassName ); return pRet; } // SbFormFactory, show user forms by: dim as new <user form name> -SbxBase* SbFormFactory::Create( sal_uInt16, sal_uInt32 ) +SbxBaseRef SbFormFactory::Create( sal_uInt16, sal_uInt32 ) { // Not supported return nullptr; } -SbxObject* SbFormFactory::CreateObject( const OUString& rClassName ) +SbxObjectRef SbFormFactory::CreateObject( const OUString& rClassName ) { if( SbModule* pMod = GetSbData()->pMod ) { @@ -514,10 +514,10 @@ SbxObject* SbFormFactory::CreateObject( const OUString& rClassName ) // SbTypeFactory -SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ) +SbxObjectRef cloneTypeObjectImpl( const SbxObject& rTypeObj ) { - SbxObject* pRet = new SbxObject( rTypeObj ); - pRet->PutObject( pRet ); + SbxObjectRef pRet = new SbxObject( rTypeObj ); + pRet->PutObject( pRet.get() ); // Copy the properties, not only the reference to them SbxArray* pProps = pRet->GetProperties(); @@ -562,10 +562,10 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ) { SbxBase* pObjBase = pVar->GetObject(); SbxObject* pSrcObj = dynamic_cast<SbxObject*>( pObjBase ); - SbxObject* pDestObj = nullptr; + SbxObjectRef pDestObj; if( pSrcObj != nullptr ) pDestObj = cloneTypeObjectImpl( *pSrcObj ); - pNewProp->PutObject( pDestObj ); + pNewProp->PutObject( pDestObj.get() ); } pProps->PutDirect( pNewProp, i ); } @@ -573,15 +573,15 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ) return pRet; } -SbxBase* SbTypeFactory::Create( sal_uInt16, sal_uInt32 ) +SbxBaseRef SbTypeFactory::Create( sal_uInt16, sal_uInt32 ) { // Not supported return nullptr; } -SbxObject* SbTypeFactory::CreateObject( const OUString& rClassName ) +SbxObjectRef SbTypeFactory::CreateObject( const OUString& rClassName ) { - SbxObject* pRet = nullptr; + SbxObjectRef pRet; SbModule* pMod = GetSbData()->pMod; if( pMod ) { @@ -594,9 +594,9 @@ SbxObject* SbTypeFactory::CreateObject( const OUString& rClassName ) return pRet; } -SbxObject* createUserTypeImpl( const OUString& rClassName ) +SbxObjectRef createUserTypeImpl( const OUString& rClassName ) { - SbxObject* pRetObj = GetSbData()->pTypeFac->CreateObject( rClassName ); + SbxObjectRef pRetObj = GetSbData()->pTypeFac->CreateObject( rClassName ); return pRetObj; } @@ -609,7 +609,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) aOUSource = pClassModule->aOUSource; aComment = pClassModule->aComment; // see comment in destructor about these two - pImage = pClassModule->pImage; + pImage.reset(pClassModule->pImage.get()); pBreaks = pClassModule->pBreaks; SetClassName( pClassModule->GetName() ); @@ -755,7 +755,7 @@ SbClassModuleObject::~SbClassModuleObject() // prevent the base class destructor from deleting these because // we do not actually own them - pImage = nullptr; + pImage.release(); pBreaks = nullptr; } @@ -852,13 +852,13 @@ void SbClassFactory::RemoveClassModule( SbModule* pClassModule ) xClassModules->Remove( pClassModule ); } -SbxBase* SbClassFactory::Create( sal_uInt16, sal_uInt32 ) +SbxBaseRef SbClassFactory::Create( sal_uInt16, sal_uInt32 ) { // Not supported return nullptr; } -SbxObject* SbClassFactory::CreateObject( const OUString& rClassName ) +SbxObjectRef SbClassFactory::CreateObject( const OUString& rClassName ) { SbxObjectRef xToUseClassModules = xClassModules; @@ -873,7 +873,7 @@ SbxObject* SbClassFactory::CreateObject( const OUString& rClassName ) } } SbxVariable* pVar = xToUseClassModules->Find( rClassName, SbxClassType::Object ); - SbxObject* pRet = nullptr; + SbxObjectRef pRet; if( pVar ) { SbModule* pVarMod = static_cast<SbModule*>(pVar); @@ -1802,8 +1802,8 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer ) } for (sal_uInt16 i = 0; i < nMod; ++i) { - SbxBase* pBase = SbxBase::Load( r ); - SbModule* pMod = dynamic_cast<SbModule*>(pBase); + SbxBaseRef pBase = SbxBase::Load( r ); + SbModule* pMod = dynamic_cast<SbModule*>(pBase.get()); if( !pMod ) { return false; diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 15c5e3778201..f4dbd35e3b6c 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -2848,7 +2848,7 @@ Any SbUnoObject::getUnoAny() } // help method to create a Uno-Struct per CoreReflection -static SbUnoObject* Impl_CreateUnoStruct( const OUString& aClassName ) +static SbUnoObjectRef Impl_CreateUnoStruct( const OUString& aClassName ) { // get CoreReflection Reference< XIdlReflection > xCoreReflection = getCoreReflection_Impl(); @@ -2873,21 +2873,21 @@ static SbUnoObject* Impl_CreateUnoStruct( const OUString& aClassName ) Any aNewAny; xClass->createObject( aNewAny ); // make a SbUnoObject out of it - SbUnoObject* pUnoObj = new SbUnoObject( aClassName, aNewAny ); + SbUnoObjectRef pUnoObj = new SbUnoObject( aClassName, aNewAny ); return pUnoObj; } // Factory-Class to create Uno-Structs per DIM AS NEW -SbxBase* SbUnoFactory::Create( sal_uInt16, sal_uInt32 ) +SbxBaseRef SbUnoFactory::Create( sal_uInt16, sal_uInt32 ) { // Via SbxId nothing works in Uno return nullptr; } -SbxObject* SbUnoFactory::CreateObject( const OUString& rClassName ) +SbxObjectRef SbUnoFactory::CreateObject( const OUString& rClassName ) { - return Impl_CreateUnoStruct( rClassName ); + return Impl_CreateUnoStruct( rClassName ).get(); } diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index a69a3f508ec7..df69b7dc6e6b 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -417,7 +417,7 @@ static bool getDefaultVBAMode( StarBASIC* pb ) SbModule::SbModule( const OUString& rName, bool bVBACompat ) : SbxObject( "StarBASICModule" ), - pImage(nullptr), pBreaks(nullptr), mbVBACompat( bVBACompat ), bIsProxyModule( false ) + pBreaks(nullptr), mbVBACompat( bVBACompat ), bIsProxyModule( false ) { SetName( rName ); SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch ); @@ -434,7 +434,7 @@ SbModule::SbModule( const OUString& rName, bool bVBACompat ) SbModule::~SbModule() { SAL_INFO("basic","Module named " << GetName() << " is destructing"); - delete pImage; + pImage.reset(); delete pBreaks; pClassData.reset(); mxWrapper = nullptr; @@ -465,7 +465,7 @@ const SbxObject* SbModule::FindType( const OUString& aTypeName ) const void SbModule::StartDefinitions() { - delete pImage; pImage = nullptr; + pImage.reset(); if( pClassData ) pClassData->clear(); @@ -557,11 +557,11 @@ void SbModule::GetProcedureProperty( const OUString& rName, SbxDataType t ) } if( !pProp ) { - pProp = new SbProcedureProperty( rName, t ); - pProp->SetFlag( SbxFlagBits::ReadWrite ); - pProp->SetParent( this ); - pProps->Put(pProp, pProps->Count()); - StartListening(pProp->GetBroadcaster(), DuplicateHandling::Prevent); + tools::SvRef<SbProcedureProperty> pNewProp = new SbProcedureProperty( rName, t ); + pNewProp->SetFlag( SbxFlagBits::ReadWrite ); + pNewProp->SetParent( this ); + pProps->Put(pNewProp.get(), pProps->Count()); + StartListening(pNewProp->GetBroadcaster(), DuplicateHandling::Prevent); } } @@ -615,7 +615,7 @@ void SbModule::EndDefinitions( bool bNewState ) void SbModule::Clear() { - delete pImage; pImage = nullptr; + pImage.reset(); if( pClassData ) pClassData->clear(); SbxObject::Clear(); @@ -1571,7 +1571,7 @@ void SbModule::fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg ) const { if ( !pImg ) - pImg = pImage; + pImg = pImage.get(); for (sal_uInt32 i = 0; i < pMethods->Count(); i++) { SbMethod* pMeth = dynamic_cast<SbMethod*>(pMethods->Get(i)); @@ -1598,18 +1598,17 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) rStrm.ReadUChar( bImage ); if( bImage ) { - SbiImage* p = new SbiImage; + std::unique_ptr<SbiImage> p(new SbiImage); sal_uInt32 nImgVer = 0; if( !p->Load( rStrm, nImgVer ) ) { - delete p; return false; } // If the image is in old format, we fix up the method start offsets if ( nImgVer < B_EXT_IMG_VERSION ) { - fixUpMethodStart( false, p ); + fixUpMethodStart( false, p.get() ); p->ReleaseLegacyBuffer(); } aComment = p->aComment; @@ -1621,15 +1620,13 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) if( nVer == 1 ) { SetSource32( p->aOUSource ); - delete p; } else - pImage = p; + pImage = std::move(p); } else { SetSource32( p->aOUSource ); - delete p; } } return true; @@ -2098,24 +2095,23 @@ void SbMethod::Broadcast( SfxHintId nHintId ) // Block broadcasts while creating new method std::unique_ptr<SfxBroadcaster> pSaveBroadcaster = std::move(mpBroadcaster); - SbMethod* pThisCopy = new SbMethod( *this ); - SbMethodRef xHolder = pThisCopy; + SbMethodRef xThisCopy = new SbMethod( *this ); if( mpPar.is() ) { // Enregister this as element 0, but don't reset the parent! if( GetType() != SbxVOID ) { - mpPar->PutDirect( pThisCopy, 0 ); + mpPar->PutDirect( xThisCopy.get(), 0 ); } SetParameters( nullptr ); } mpBroadcaster = std::move(pSaveBroadcaster); - mpBroadcaster->Broadcast( SbxHint( nHintId, pThisCopy ) ); + mpBroadcaster->Broadcast( SbxHint( nHintId, xThisCopy.get() ) ); SbxFlagBits nSaveFlags = GetFlags(); SetFlag( SbxFlagBits::ReadWrite ); pSaveBroadcaster = std::move(mpBroadcaster); - Put( pThisCopy->GetValues_Impl() ); + Put( xThisCopy->GetValues_Impl() ); mpBroadcaster = std::move(pSaveBroadcaster); SetFlags( nSaveFlags ); } |