summaryrefslogtreecommitdiffstats
path: root/basic
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-10 14:14:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-10 15:14:48 +0200
commit0afb2b63b38dff138e66f4ac8afed60911cb6aad (patch)
tree6f0d5e837600a460a57fce6383bc4eef10cdfc7a /basic
parentI suspect that we unlikely to use JRE older than 1.3.1_07 (diff)
downloadcore-0afb2b63b38dff138e66f4ac8afed60911cb6aad.tar.gz
core-0afb2b63b38dff138e66f4ac8afed60911cb6aad.zip
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')
-rw-r--r--basic/inc/sb.hxx4
-rw-r--r--basic/inc/sbstdobj.hxx2
-rw-r--r--basic/inc/sbxfac.hxx4
-rw-r--r--basic/source/basmgr/basmgr.cxx6
-rw-r--r--basic/source/classes/image.cxx4
-rw-r--r--basic/source/classes/sb.cxx48
-rw-r--r--basic/source/classes/sbunoobj.cxx10
-rw-r--r--basic/source/classes/sbxmod.cxx38
-rw-r--r--basic/source/comp/codegen.cxx8
-rw-r--r--basic/source/comp/dim.cxx4
-rw-r--r--basic/source/inc/sbintern.hxx20
-rw-r--r--basic/source/inc/sbunoobj.hxx4
-rw-r--r--basic/source/runtime/runtime.cxx22
-rw-r--r--basic/source/runtime/stdobj1.cxx2
-rw-r--r--basic/source/sbx/sbxarray.cxx2
-rw-r--r--basic/source/sbx/sbxbase.cxx16
-rw-r--r--basic/source/sbx/sbxobj.cxx10
-rw-r--r--basic/source/sbx/sbxvalue.cxx5
18 files changed, 102 insertions, 107 deletions
diff --git a/basic/inc/sb.hxx b/basic/inc/sb.hxx
index f94c52a6e045..19a591219d11 100644
--- a/basic/inc/sb.hxx
+++ b/basic/inc/sb.hxx
@@ -22,8 +22,8 @@
#include <basic/sbxobj.hxx>
// create object from user-type (+StringID+StringID)
-SbxObject* createUserTypeImpl(const OUString& rClassName);
+SbxObjectRef createUserTypeImpl(const OUString& rClassName);
-SbxObject* cloneTypeObjectImpl(const SbxObject& rTypeObj);
+SbxObjectRef cloneTypeObjectImpl(const SbxObject& rTypeObj);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/inc/sbstdobj.hxx b/basic/inc/sbstdobj.hxx
index 001e332ae245..69db5c9ba9d5 100644
--- a/basic/inc/sbstdobj.hxx
+++ b/basic/inc/sbstdobj.hxx
@@ -28,7 +28,7 @@ class SbStdFactory final : public SbxFactory
public:
SbStdFactory();
- virtual SbxObject* CreateObject( const OUString& rClassName ) override;
+ virtual SbxObjectRef CreateObject( const OUString& rClassName ) override;
};
class SbStdPicture final : public SbxObject
diff --git a/basic/inc/sbxfac.hxx b/basic/inc/sbxfac.hxx
index 28257b17a6d7..ab0736f3006e 100644
--- a/basic/inc/sbxfac.hxx
+++ b/basic/inc/sbxfac.hxx
@@ -29,8 +29,8 @@ class SbxFactory
public:
virtual ~SbxFactory();
SbxFactory() {}
- virtual SbxBase* Create(sal_uInt16 nSbxId, sal_uInt32);
- virtual SbxObject* CreateObject(const OUString&);
+ virtual SbxBaseRef Create(sal_uInt16 nSbxId, sal_uInt32);
+ virtual SbxObjectRef CreateObject(const OUString&);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 41882928a81d..1cbd407f2171 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -1784,12 +1784,12 @@ static uno::Sequence< sal_Int8 > implGetDialogData( SbxObject* pDialog )
return aData;
}
-static SbxObject* implCreateDialog( const uno::Sequence< sal_Int8 >& aData )
+static SbxObjectRef implCreateDialog( const uno::Sequence< sal_Int8 >& aData )
{
sal_Int8* pData = const_cast< uno::Sequence< sal_Int8 >& >(aData).getArray();
SvMemoryStream aMemStream( pData, aData.getLength(), StreamMode::READ );
- SbxBase* pBase = SbxBase::Load( aMemStream );
- return dynamic_cast<SbxObject*>(pBase);
+ SbxBaseRef pBase = SbxBase::Load( aMemStream );
+ return dynamic_cast<SbxObject*>(pBase.get());
}
// HACK! Because this value is defined in basctl/inc/vcsbxdef.hxx
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 );
}
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx
index 565fafe6c079..3442202a8ba1 100644
--- a/basic/source/comp/codegen.cxx
+++ b/basic/source/comp/codegen.cxx
@@ -139,7 +139,7 @@ void SbiCodeGen::Save()
if( pParser->IsCodeCompleting() )
return;
- SbiImage* p = new SbiImage;
+ std::unique_ptr<SbiImage> p(new SbiImage);
rMod.StartDefinitions();
// OPTION BASE-Value:
p->nDimBase = pParser->nBase;
@@ -385,11 +385,7 @@ void SbiCodeGen::Save()
}
if( !p->IsError() )
{
- rMod.pImage = p;
- }
- else
- {
- delete p;
+ rMod.pImage = std::move(p);
}
rMod.EndDefinitions();
}
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index cf14d1c7818c..56bbab29587a 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -691,8 +691,8 @@ void SbiParser::DefType()
SbxObject* pTypeObj = static_cast< SbxObject* >( rTypeArray->Find( aTypeName, SbxClassType::Object ) );
if( pTypeObj != nullptr )
{
- SbxObject* pCloneObj = cloneTypeObjectImpl( *pTypeObj );
- pTypeElem->PutObject( pCloneObj );
+ SbxObjectRef pCloneObj = cloneTypeObjectImpl( *pTypeObj );
+ pTypeElem->PutObject( pCloneObj.get() );
}
}
}
diff --git a/basic/source/inc/sbintern.hxx b/basic/source/inc/sbintern.hxx
index ea119593340e..d4bed5bf845e 100644
--- a/basic/source/inc/sbintern.hxx
+++ b/basic/source/inc/sbintern.hxx
@@ -39,8 +39,8 @@ class BasicManager;
class SbiFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
};
struct SbClassData
@@ -70,8 +70,8 @@ public:
void AddClassModule( SbModule* pClassModule );
void RemoveClassModule( SbModule* pClassModule );
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
SbModule* FindClass( const OUString& rClassName );
};
@@ -80,23 +80,23 @@ public:
class SbTypeFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
};
class SbFormFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
};
// Factory class to create OLE objects
class SbOLEFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
};
diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx
index 47081b7633f3..839f883ababb 100644
--- a/basic/source/inc/sbunoobj.hxx
+++ b/basic/source/inc/sbunoobj.hxx
@@ -204,8 +204,8 @@ public:
class SbUnoFactory : public SbxFactory
{
public:
- virtual SbxBase* Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
- virtual SbxObject* CreateObject( const OUString& ) override;
+ virtual SbxBaseRef Create( sal_uInt16 nSbxId, sal_uInt32 ) override;
+ virtual SbxObjectRef CreateObject( const OUString& ) override;
};
// wrapper for a uno-class
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index d1dcd3d74502..b82cf7b5f8a1 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -598,7 +598,7 @@ SbMethod* SbiInstance::GetCaller( sal_uInt16 nLevel )
SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart )
: rBasic( *static_cast<StarBASIC*>(pm->pParent) ), pInst( GetSbData()->pInst ),
- pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), mpExtCaller(nullptr), m_nLastTime(0)
+ pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() ), mpExtCaller(nullptr), m_nLastTime(0)
{
nFlags = pe ? pe->GetDebugFlags() : BasicDebugFlags::NONE;
pIosys = pInst->GetIoSystem();
@@ -4382,7 +4382,7 @@ void SbiRuntime::StepOPEN( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
OUString aClass( pImg->GetString( static_cast<short>( nOp2 ) ) );
- SbxObject *pObj = SbxBase::CreateObject( aClass );
+ SbxObjectRef pObj = SbxBase::CreateObject( aClass );
if( !pObj )
{
Error( ERRCODE_BASIC_INVALID_OBJECT );
@@ -4393,9 +4393,9 @@ void SbiRuntime::StepCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
pObj->SetName( aName );
// the object must be able to call the BASIC
pObj->SetParent( &rBasic );
- SbxVariable* pNew = new SbxVariable;
- pNew->PutObject( pObj );
- PushVar( pNew );
+ SbxVariableRef pNew = new SbxVariable;
+ pNew->PutObject( pObj.get() );
+ PushVar( pNew.get() );
}
}
@@ -4457,7 +4457,7 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
if (!bRestored || !pArray->SbxArray::GetRef(i)) // For those left unset after preserve
{
- SbxObject* pClassObj = SbxBase::CreateObject(aClass);
+ SbxObjectRef pClassObj = SbxBase::CreateObject(aClass);
if (!pClassObj)
{
Error(ERRCODE_BASIC_INVALID_OBJECT);
@@ -4470,7 +4470,7 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
pClassObj->SetName(aName);
// the object must be able to call the basic
pClassObj->SetParent(&rBasic);
- pArray->SbxArray::Put(pClassObj, i);
+ pArray->SbxArray::Put(pClassObj.get(), i);
}
}
}
@@ -4481,15 +4481,15 @@ void SbiRuntime::StepTCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
OUString aClass( pImg->GetString( static_cast<short>( nOp2 ) ) );
- SbxObject* pCopyObj = createUserTypeImpl( aClass );
+ SbxObjectRef pCopyObj = createUserTypeImpl( aClass );
if( pCopyObj )
{
pCopyObj->SetName( aName );
}
- SbxVariable* pNew = new SbxVariable;
- pNew->PutObject( pCopyObj );
+ SbxVariableRef pNew = new SbxVariable;
+ pNew->PutObject( pCopyObj.get() );
pNew->SetDeclareClassName( aClass );
- PushVar( pNew );
+ PushVar( pNew.get() );
}
void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, SbxDataType t, sal_uInt32 nOp2 )
diff --git a/basic/source/runtime/stdobj1.cxx b/basic/source/runtime/stdobj1.cxx
index d5237b6f9e8c..ee7df8d7a62d 100644
--- a/basic/source/runtime/stdobj1.cxx
+++ b/basic/source/runtime/stdobj1.cxx
@@ -44,7 +44,7 @@ SbStdFactory::SbStdFactory()
{
}
-SbxObject* SbStdFactory::CreateObject( const OUString& rClassName )
+SbxObjectRef SbStdFactory::CreateObject( const OUString& rClassName )
{
if( rClassName.equalsIgnoreAsciiCase("Picture") )
return new SbStdPicture;
diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index 06774acddc00..a54845d1c7c8 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -338,7 +338,7 @@ bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 /*nVer*/ )
{
sal_uInt16 nIdx;
rStrm.ReadUInt16( nIdx );
- SbxVariable* pVar = static_cast<SbxVariable*>(Load( rStrm ));
+ SbxVariableRef pVar = static_cast<SbxVariable*>(Load( rStrm ).get());
if( pVar )
{
SbxVariableRef& rRef = GetRef( nIdx );
diff --git a/basic/source/sbx/sbxbase.cxx b/basic/source/sbx/sbxbase.cxx
index b980e0e9e2d7..3b70307ec3e7 100644
--- a/basic/source/sbx/sbxbase.cxx
+++ b/basic/source/sbx/sbxbase.cxx
@@ -129,7 +129,7 @@ void SbxBase::RemoveFactory( SbxFactory const * pFac )
}
-SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
+SbxBaseRef SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
{
// #91626: Hack to skip old Basic dialogs
// Problem: There does not exist a factory any more,
@@ -153,7 +153,7 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
}
// Unknown type: go over the factories!
SbxAppData& r = GetSbxData_Impl();
- SbxBase* pNew = nullptr;
+ SbxBaseRef pNew;
for (auto const& rpFac : r.m_Factories)
{
pNew = rpFac->Create( nSbxId, nCreator );
@@ -164,10 +164,10 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
return pNew;
}
-SbxObject* SbxBase::CreateObject( const OUString& rClass )
+SbxObjectRef SbxBase::CreateObject( const OUString& rClass )
{
SbxAppData& r = GetSbxData_Impl();
- SbxObject* pNew = nullptr;
+ SbxObjectRef pNew;
for (auto const& rpFac : r.m_Factories)
{
pNew = rpFac->CreateObject( rClass );
@@ -191,7 +191,7 @@ namespace {
}
-SbxBase* SbxBase::Load( SvStream& rStrm )
+SbxBaseRef SbxBase::Load( SvStream& rStrm )
{
sal_uInt16 nSbxId(0), nFlagsTmp(0), nVer(0);
sal_uInt32 nCreator(0), nSize(0);
@@ -200,7 +200,7 @@ SbxBase* SbxBase::Load( SvStream& rStrm )
sal_uInt64 nOldPos = rStrm.Tell();
rStrm.ReadUInt32( nSize );
- SbxBase* p = Create( nSbxId, nCreator );
+ SbxBaseRef p = Create( nSbxId, nCreator );
if( p )
{
p->nFlags = nFlags;
@@ -267,12 +267,12 @@ SbxFactory::~SbxFactory()
{
}
-SbxBase* SbxFactory::Create( sal_uInt16, sal_uInt32 )
+SbxBaseRef SbxFactory::Create( sal_uInt16, sal_uInt32 )
{
return nullptr;
}
-SbxObject* SbxFactory::CreateObject( const OUString& )
+SbxObjectRef SbxFactory::CreateObject( const OUString& )
{
return nullptr;
}
diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx
index 6beae9ac7ffe..7f3560a62003 100644
--- a/basic/source/sbx/sbxobj.cxx
+++ b/basic/source/sbx/sbxobj.cxx
@@ -364,7 +364,7 @@ SbxVariable* SbxObject::Make( const OUString& rName, SbxClassType ct, SbxDataTyp
return pRes;
}
}
- SbxVariable* pVar = nullptr;
+ SbxVariableRef pVar;
switch( ct )
{
case SbxClassType::Variable:
@@ -375,17 +375,17 @@ SbxVariable* SbxObject::Make( const OUString& rName, SbxClassType ct, SbxDataTyp
pVar = new SbxMethod( rName, dt, bIsRuntimeFunction );
break;
case SbxClassType::Object:
- pVar = CreateObject( rName );
+ pVar = CreateObject( rName ).get();
break;
default:
break;
}
pVar->SetParent( this );
- pArray->Put(pVar, pArray->Count());
+ pArray->Put(pVar.get(), pArray->Count());
SetModified( true );
// The object listen always
StartListening(pVar->GetBroadcaster(), DuplicateHandling::Prevent);
- return pVar;
+ return pVar.get();
}
void SbxObject::Insert( SbxVariable* pVar )
@@ -532,7 +532,7 @@ void SbxObject::Remove( SbxVariable* pVar )
static bool LoadArray( SvStream& rStrm, SbxObject* pThis, SbxArray* pArray )
{
- SbxArrayRef p = static_cast<SbxArray*>( SbxBase::Load( rStrm ) );
+ SbxArrayRef p = static_cast<SbxArray*>( SbxBase::Load( rStrm ).get() );
if( !p.is() )
{
return false;
diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx
index 403a7f842554..e67044def3f3 100644
--- a/basic/source/sbx/sbxvalue.cxx
+++ b/basic/source/sbx/sbxvalue.cxx
@@ -1383,11 +1383,14 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
aData.pObj = nullptr;
break;
case 1:
- aData.pObj = SbxBase::Load( r );
+ {
+ auto ref = SbxBase::Load( r );
+ aData.pObj = ref.get();
// if necessary increment Ref-Count
if (aData.pObj)
aData.pObj->AddFirstRef();
return ( aData.pObj != nullptr );
+ }
case 2:
aData.pObj = this;
break;