[Libreoffice-commits] core.git: connectivity/source include/connectivity

Noel (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 22 12:39:15 UTC 2021


 connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx |   38 ++++----
 connectivity/source/commontools/TColumnsHelper.cxx             |    2 
 connectivity/source/commontools/TDatabaseMetaDataBase.cxx      |    5 -
 connectivity/source/commontools/TIndexColumns.cxx              |   21 ++--
 connectivity/source/commontools/TIndexes.cxx                   |    3 
 connectivity/source/commontools/TKeyColumns.cxx                |   25 ++---
 connectivity/source/commontools/TKeys.cxx                      |    6 -
 connectivity/source/commontools/dbtools.cxx                    |    9 --
 connectivity/source/commontools/dbtools2.cxx                   |    3 
 connectivity/source/commontools/parameters.cxx                 |    9 --
 connectivity/source/commontools/predicateinput.cxx             |    2 
 connectivity/source/cpool/ZPoolCollection.cxx                  |    6 -
 connectivity/source/drivers/calc/CConnection.cxx               |    6 -
 connectivity/source/drivers/calc/CDatabaseMetaData.cxx         |    7 -
 connectivity/source/drivers/calc/CDriver.cxx                   |    5 -
 connectivity/source/drivers/calc/CTable.cxx                    |    5 -
 connectivity/source/drivers/calc/CTables.cxx                   |    5 -
 connectivity/source/drivers/component/CDatabaseMetaData.cxx    |   10 --
 connectivity/source/drivers/dbase/DConnection.cxx              |    7 -
 connectivity/source/drivers/dbase/DDatabaseMetaData.cxx        |   15 +--
 connectivity/source/drivers/dbase/DDriver.cxx                  |    5 -
 connectivity/source/drivers/dbase/DIndexes.cxx                 |    2 
 connectivity/source/drivers/dbase/DTable.cxx                   |    4 
 connectivity/source/drivers/dbase/DTables.cxx                  |    5 -
 connectivity/source/drivers/file/FColumns.cxx                  |    3 
 connectivity/source/drivers/file/FConnection.cxx               |    3 
 connectivity/source/drivers/file/FDatabaseMetaData.cxx         |   19 +---
 connectivity/source/drivers/file/FDriver.cxx                   |    5 -
 connectivity/source/drivers/firebird/DatabaseMetaData.cxx      |   45 ++++------
 connectivity/source/drivers/firebird/Driver.cxx                |    5 -
 connectivity/source/drivers/flat/EConnection.cxx               |   16 +--
 connectivity/source/drivers/flat/EDatabaseMetaData.cxx         |   10 --
 connectivity/source/drivers/flat/EDriver.cxx                   |    5 -
 connectivity/source/drivers/flat/ETable.cxx                    |    5 -
 connectivity/source/drivers/flat/ETables.cxx                   |    5 -
 connectivity/source/drivers/hsqldb/HDriver.cxx                 |    2 
 connectivity/source/drivers/hsqldb/HTable.cxx                  |    9 --
 connectivity/source/drivers/hsqldb/HTables.cxx                 |    3 
 connectivity/source/drivers/hsqldb/HUsers.cxx                  |    3 
 connectivity/source/drivers/hsqldb/HViews.cxx                  |    3 
 connectivity/source/drivers/jdbc/DatabaseMetaData.cxx          |    2 
 connectivity/source/drivers/jdbc/JConnection.cxx               |    6 -
 connectivity/source/drivers/jdbc/JDriver.cxx                   |    2 
 connectivity/source/drivers/mysql_jdbc/YTable.cxx              |   11 +-
 connectivity/source/drivers/mysql_jdbc/YTables.cxx             |    7 -
 connectivity/source/drivers/mysql_jdbc/YUsers.cxx              |    6 -
 connectivity/source/drivers/mysql_jdbc/YViews.cxx              |    2 
 connectivity/source/drivers/mysqlc/mysqlc_driver.cxx           |    5 -
 connectivity/source/drivers/odbc/ODatabaseMetaData.cxx         |   37 ++++----
 connectivity/source/drivers/odbc/ODriver.cxx                   |    5 -
 connectivity/source/drivers/odbc/OPreparedStatement.cxx        |    4 
 connectivity/source/drivers/odbc/OStatement.cxx                |    4 
 connectivity/source/drivers/writer/WConnection.cxx             |    7 -
 connectivity/source/drivers/writer/WDatabaseMetaData.cxx       |    8 -
 connectivity/source/drivers/writer/WDriver.cxx                 |    5 -
 connectivity/source/drivers/writer/WTable.cxx                  |    5 -
 connectivity/source/drivers/writer/WTables.cxx                 |   12 +-
 connectivity/source/inc/odbc/OPreparedStatement.hxx            |    2 
 connectivity/source/inc/odbc/OStatement.hxx                    |    2 
 connectivity/source/parse/PColumn.cxx                          |    6 -
 connectivity/source/parse/sqliterator.cxx                      |   41 ++++-----
 connectivity/source/sdbcx/VColumn.cxx                          |    3 
 connectivity/source/sdbcx/VTable.cxx                           |    2 
 include/connectivity/PColumn.hxx                               |    2 
 64 files changed, 227 insertions(+), 305 deletions(-)

New commits:
commit dffe94959ada5297c7c719497395f5dfe66c4d2f
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Mon Feb 22 10:48:51 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Feb 22 13:37:53 2021 +0100

    loplugin:refcounting in connectivity
    
    Change-Id: Iff2f096e7ee00d9cb29d47462dd7e1963c6b06e0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111302
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
index 24be4d72a6ce..75d0a04dc22a 100644
--- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
+++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
@@ -496,128 +496,126 @@ Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings(  )
 
 void ODatabaseMetaDataResultSet::setProceduresMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setProceduresMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setCatalogsMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setCatalogsMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setSchemasMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setSchemasMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setColumnPrivilegesMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setColumnsMap()
 {
-
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setColumnsMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setTablesMap()
 {
-
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setTablesMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setProcedureColumnsMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setPrimaryKeysMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setIndexInfoMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setIndexInfoMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setTablePrivilegesMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setCrossReferenceMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setCrossReferenceMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setVersionColumnsMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setVersionColumnsMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setBestRowIdentifierMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setBestRowIdentifierMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setTypeInfoMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setTypeInfoMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setUDTsMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setUDTsMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setTableTypes()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setTableTypes();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setExportedKeysMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setExportedKeysMap();
     m_xMetaData = pMetaData;
 }
 
 void ODatabaseMetaDataResultSet::setImportedKeysMap()
 {
-    ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
+    rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData();
     pMetaData->setImportedKeysMap();
     m_xMetaData = pMetaData;
 }
diff --git a/connectivity/source/commontools/TColumnsHelper.cxx b/connectivity/source/commontools/TColumnsHelper.cxx
index 8671df0b042f..f81eca9f0a90 100644
--- a/connectivity/source/commontools/TColumnsHelper.cxx
+++ b/connectivity/source/commontools/TColumnsHelper.cxx
@@ -111,7 +111,7 @@ sdbcx::ObjectType OColumnsHelper::createObject(const OUString& _rName)
         m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= aCatalog;
         m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME))  >>= aSchema;
         m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))        >>= aTable;
-        connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName,
+        rtl::Reference<connectivity::sdbcx::OColumn> pRet = new connectivity::sdbcx::OColumn(_rName,
                                                 pColDesc->aField6,
                                                 pColDesc->sField13,
                                                 pColDesc->sField12,
diff --git a/connectivity/source/commontools/TDatabaseMetaDataBase.cxx b/connectivity/source/commontools/TDatabaseMetaDataBase.cxx
index e5823278095e..325d0ff067c8 100644
--- a/connectivity/source/commontools/TDatabaseMetaDataBase.cxx
+++ b/connectivity/source/commontools/TDatabaseMetaDataBase.cxx
@@ -163,10 +163,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo(  )
             m_aTypeInfoRows = aTypeInfoRows;
         }
     }
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
-    Reference< XResultSet > xRet = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
     pResult->setRows(m_aTypeInfoRows);
-    return xRet;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys(
diff --git a/connectivity/source/commontools/TIndexColumns.cxx b/connectivity/source/commontools/TIndexColumns.cxx
index bbb5ca706f20..1db4426c1888 100644
--- a/connectivity/source/commontools/TIndexColumns.cxx
+++ b/connectivity/source/commontools/TIndexColumns.cxx
@@ -82,17 +82,16 @@ sdbcx::ObjectType OIndexColumns::createObject(const OUString& _rName)
                 sal_Int32 nNull = xRow->getInt(11);
                 OUString aColumnDef(xRow->getString(13));
 
-                OIndexColumn* pRet = new OIndexColumn(bAsc,
-                                                      _rName,
-                                                      aTypeName,
-                                                      aColumnDef,
-                                                      nNull,
-                                                      nSize,
-                                                      nDec,
-                                                      nDataType,
-                                                      true,
-                                                      aCatalog, aSchema, aTable);
-                xRet = pRet;
+                xRet = new OIndexColumn(bAsc,
+                                        _rName,
+                                        aTypeName,
+                                        aColumnDef,
+                                        nNull,
+                                        nSize,
+                                        nDec,
+                                        nDataType,
+                                        true,
+                                        aCatalog, aSchema, aTable);
                 break;
             }
         }
diff --git a/connectivity/source/commontools/TIndexes.cxx b/connectivity/source/commontools/TIndexes.cxx
index 5a8c7c29a0f4..b0998b5b3a79 100644
--- a/connectivity/source/commontools/TIndexes.cxx
+++ b/connectivity/source/commontools/TIndexes.cxx
@@ -101,10 +101,9 @@ sdbcx::ObjectType OIndexesHelper::createObject(const OUString& _rName)
                 catch(const Exception&)
                 {
                 }
-                OIndexHelper* pRet = new OIndexHelper(m_pTable,aName,aQualifier,bUnique,
+                xRet = new OIndexHelper(m_pTable,aName,aQualifier,bUnique,
                     bPrimarKeyIndex,
                     nClustered == IndexType::CLUSTERED);
-                xRet = pRet;
                 break;
             }
         }
diff --git a/connectivity/source/commontools/TKeyColumns.cxx b/connectivity/source/commontools/TKeyColumns.cxx
index acbfc54bf000..0a2c02bb22bb 100644
--- a/connectivity/source/commontools/TKeyColumns.cxx
+++ b/connectivity/source/commontools/TKeyColumns.cxx
@@ -99,19 +99,18 @@ sdbcx::ObjectType OKeyColumnsHelper::createObject(const OUString& _rName)
                     // sometimes we get an error when asking for this param
                 }
 
-                OKeyColumn* pRet = new OKeyColumn(aRefColumnName,
-                                                  _rName,
-                                                  aTypeName,
-                                                  sColumnDef,
-                                                  nNull,
-                                                  nSize,
-                                                  nDec,
-                                                  nDataType,
-                                                  isCaseSensitive(),
-                                                  aCatalog,
-                                                  aSchema,
-                                                  aTable);
-                xRet = pRet;
+                xRet = new OKeyColumn(aRefColumnName,
+                                    _rName,
+                                    aTypeName,
+                                    sColumnDef,
+                                    nNull,
+                                    nSize,
+                                    nDec,
+                                    nDataType,
+                                    isCaseSensitive(),
+                                    aCatalog,
+                                    aSchema,
+                                    aTable);
             }
         }
     }
diff --git a/connectivity/source/commontools/TKeys.cxx b/connectivity/source/commontools/TKeys.cxx
index 4c223624dc3d..ab16752677b5 100644
--- a/connectivity/source/commontools/TKeys.cxx
+++ b/connectivity/source/commontools/TKeys.cxx
@@ -57,14 +57,12 @@ sdbcx::ObjectType OKeysHelper::createObject(const OUString& _rName)
 
     if(!_rName.isEmpty())
     {
-        OTableKeyHelper* pRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName));
-        xRet = pRet;
+        xRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName));
     }
 
     if(!xRet.is()) // we have a primary key with a system name
     {
-        OTableKeyHelper* pRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName));
-        xRet = pRet;
+        xRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName));
     }
 
     return xRet;
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx
index 31e54c1b0606..fef22a3b2196 100644
--- a/connectivity/source/commontools/dbtools.cxx
+++ b/connectivity/source/commontools/dbtools.cxx
@@ -1713,21 +1713,20 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer,
     }
     // build an interaction request
     // two continuations (Ok and Cancel)
-    OInteractionAbort* pAbort = new OInteractionAbort;
-    OParameterContinuation* pParams = new OParameterContinuation;
+    rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort;
+    rtl::Reference<OParameterContinuation> pParams = new OParameterContinuation;
     // the request
     ParametersRequest aRequest;
     Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies);
     aRequest.Parameters = xWrappedParameters;
     aRequest.Connection = _xConnection;
-    OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
-    Reference< XInteractionRequest > xRequest(pRequest);
+    rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(makeAny(aRequest));
     // some knittings
     pRequest->addContinuation(pAbort);
     pRequest->addContinuation(pParams);
 
     // execute the request
-    _rxHandler->handle(xRequest);
+    _rxHandler->handle(pRequest);
 
     if (!pParams->wasSelected())
     {
diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx
index ecc2f4f8f221..907bc7fd3698 100644
--- a/connectivity/source/commontools/dbtools2.cxx
+++ b/connectivity/source/commontools/dbtools2.cxx
@@ -484,7 +484,7 @@ namespace
                         }
                     }
 
-                    connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName,
+                    xProp = new connectivity::sdbcx::OColumn(_rName,
                                                 aField6,
                                                 sField13,
                                                 sField12,
@@ -500,7 +500,6 @@ namespace
                                                 _aSchema,
                                                 _aTable);
 
-                    xProp = pRet;
                     break;
                 }
             }
diff --git a/connectivity/source/commontools/parameters.cxx b/connectivity/source/commontools/parameters.cxx
index 906dbc0d3f27..a0b0b57958fc 100644
--- a/connectivity/source/commontools/parameters.cxx
+++ b/connectivity/source/commontools/parameters.cxx
@@ -643,15 +643,14 @@ namespace dbtools
         OSL_ENSURE ( _rxCompletionHandler.is(), "ParameterManager::completeParameters: invalid interaction handler!" );
 
         // two continuations (Ok and Cancel)
-        OInteractionAbort* pAbort = new OInteractionAbort;
-        OParameterContinuation* pParams = new OParameterContinuation;
+        rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort;
+        rtl::Reference<OParameterContinuation> pParams = new OParameterContinuation;
 
         // the request
         ParametersRequest aRequest;
         aRequest.Parameters = m_pOuterParameters.get();
         aRequest.Connection = _rxConnection;
-        OInteractionRequest* pRequest = new OInteractionRequest( makeAny( aRequest ) );
-        Reference< XInteractionRequest > xRequest( pRequest );
+        rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest( makeAny( aRequest ) );
 
         // some knittings
         pRequest->addContinuation( pAbort );
@@ -660,7 +659,7 @@ namespace dbtools
         // execute the request
         try
         {
-            _rxCompletionHandler->handle( xRequest );
+            _rxCompletionHandler->handle( pRequest );
         }
         catch( const Exception& )
         {
diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx
index f34ad6228532..37a0d6862c62 100644
--- a/connectivity/source/commontools/predicateinput.cxx
+++ b/connectivity/source/commontools/predicateinput.cxx
@@ -308,7 +308,7 @@ namespace dbtools
         }
 
         Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
-        parse::OParseColumn* pColumn = new parse::OParseColumn( sField,
+        rtl::Reference<parse::OParseColumn> pColumn = new parse::OParseColumn( sField,
                                                                 OUString(),
                                                                 OUString(),
                                                                 OUString(),
diff --git a/connectivity/source/cpool/ZPoolCollection.cxx b/connectivity/source/cpool/ZPoolCollection.cxx
index 17215ece7510..474490089879 100644
--- a/connectivity/source/cpool/ZPoolCollection.cxx
+++ b/connectivity/source/cpool/ZPoolCollection.cxx
@@ -281,9 +281,9 @@ OConnectionPool* OPoolCollection::getConnectionPool(const OUString& _sImplName,
         Reference<XPropertySet> xProp(_xDriverNode,UNO_QUERY);
         if(xProp.is())
             xProp->addPropertyChangeListener(getEnableNodeName(),this);
-        OConnectionPool* pConnectionPool = new OConnectionPool(_xDriver,_xDriverNode,m_xProxyFactory);
-        aFind = m_aPools.emplace(_sImplName,pConnectionPool).first;
-        pRet = aFind->second.get();
+        rtl::Reference<OConnectionPool> pConnectionPool = new OConnectionPool(_xDriver,_xDriverNode,m_xProxyFactory);
+        m_aPools.emplace(_sImplName,pConnectionPool);
+        pRet = pConnectionPool.get();
     }
 
     OSL_ENSURE(pRet, "Could not query DriverManager from ConnectionPool!");
diff --git a/connectivity/source/drivers/calc/CConnection.cxx b/connectivity/source/drivers/calc/CConnection.cxx
index 9b03d473bda1..78bbf7835169 100644
--- a/connectivity/source/drivers/calc/CConnection.cxx
+++ b/connectivity/source/drivers/calc/CConnection.cxx
@@ -221,8 +221,7 @@ css::uno::Reference< XTablesSupplier > OCalcConnection::createCatalog()
     Reference< XTablesSupplier > xTab = m_xCatalog;
     if(!xTab.is())
     {
-        OCalcCatalog *pCat = new OCalcCatalog(this);
-        xTab = pCat;
+        xTab = new OCalcCatalog(this);
         m_xCatalog = xTab;
     }
     return xTab;
@@ -247,8 +246,7 @@ Reference< XPreparedStatement > SAL_CALL OCalcConnection::prepareStatement( cons
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    auto pStmt = new connectivity::component::OComponentPreparedStatement(this);
-    Reference< XPreparedStatement > xHoldAlive = pStmt;
+    rtl::Reference<connectivity::component::OComponentPreparedStatement> pStmt = new connectivity::component::OComponentPreparedStatement(this);
     pStmt->construct(sql);
     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
     return pStmt;
diff --git a/connectivity/source/drivers/calc/CDatabaseMetaData.cxx b/connectivity/source/drivers/calc/CDatabaseMetaData.cxx
index cea1b32c7a94..bbed24e0c5e2 100644
--- a/connectivity/source/drivers/calc/CDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/calc/CDatabaseMetaData.cxx
@@ -130,8 +130,7 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables(
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
 
     // check if ORowSetValue type is given
     // when no types are given then we have to return all tables e.g. TABLE
@@ -156,7 +155,7 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables(
         }
     }
     if(!bTableFound)
-        return xRef;
+        return pResult;
 
     // get the sheet names from the document
 
@@ -214,7 +213,7 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables(
 
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/calc/CDriver.cxx b/connectivity/source/drivers/calc/CDriver.cxx
index 324094ac04df..b7b11cc29176 100644
--- a/connectivity/source/drivers/calc/CDriver.cxx
+++ b/connectivity/source/drivers/calc/CDriver.cxx
@@ -68,12 +68,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url,
     if ( ! acceptsURL(url) )
         return nullptr;
 
-    OCalcConnection* pCon = new OCalcConnection(this);
+    rtl::Reference<OCalcConnection> pCon = new OCalcConnection(this);
     pCon->construct(url,info);
-    Reference< XConnection > xCon = pCon;
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx
index 56214c9f3881..f2c50362ab30 100644
--- a/connectivity/source/drivers/calc/CTable.cxx
+++ b/connectivity/source/drivers/calc/CTable.cxx
@@ -486,13 +486,12 @@ void OCalcTable::fillColumns()
             aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase);
         }
 
-        sdbcx::OColumn* pColumn = new sdbcx::OColumn( aAlias, aTypeName, OUString(),OUString(),
+        rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn( aAlias, aTypeName, OUString(),OUString(),
                                                 ColumnValue::NULLABLE, nPrecision, nDecimals,
                                                 eType, false, false, bCurrency,
                                                 bStoresMixedCaseQuotedIdentifiers,
                                                 m_CatalogName, getSchema(), getName());
-        Reference< XPropertySet> xCol = pColumn;
-        m_aColumns->push_back(xCol);
+        m_aColumns->push_back(pColumn);
         m_aTypes.push_back(eType);
     }
 }
diff --git a/connectivity/source/drivers/calc/CTables.cxx b/connectivity/source/drivers/calc/CTables.cxx
index 703ab27120c5..08e5d63e3abd 100644
--- a/connectivity/source/drivers/calc/CTables.cxx
+++ b/connectivity/source/drivers/calc/CTables.cxx
@@ -38,11 +38,10 @@ using namespace ::com::sun::star::container;
 
 sdbcx::ObjectType OCalcTables::createObject(const OUString& _rName)
 {
-    OCalcTable* pTable = new OCalcTable(this, static_cast<OCalcConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
+    rtl::Reference<OCalcTable> pTable = new OCalcTable(this, static_cast<OCalcConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
                                         _rName,"TABLE");
-    sdbcx::ObjectType xRet = pTable;
     pTable->construct();
-    return xRet;
+    return pTable;
 }
 
 
diff --git a/connectivity/source/drivers/component/CDatabaseMetaData.cxx b/connectivity/source/drivers/component/CDatabaseMetaData.cxx
index f225747a6486..ea5ca9f31879 100644
--- a/connectivity/source/drivers/component/CDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/component/CDatabaseMetaData.cxx
@@ -48,8 +48,7 @@ Reference< XResultSet > OComponentDatabaseMetaData::impl_getTypeInfo_throw(  )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
 
     static ODatabaseMetaDataResultSet::ORows aRows;
     if(aRows.empty())
@@ -119,7 +118,7 @@ Reference< XResultSet > OComponentDatabaseMetaData::impl_getTypeInfo_throw(  )
     }
 
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns(
@@ -209,11 +208,10 @@ Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns(
         }
     }
 
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxBinaryLiteralLength(  )
diff --git a/connectivity/source/drivers/dbase/DConnection.cxx b/connectivity/source/drivers/dbase/DConnection.cxx
index 7c577b7c9541..c9c7a93fa9f2 100644
--- a/connectivity/source/drivers/dbase/DConnection.cxx
+++ b/connectivity/source/drivers/dbase/DConnection.cxx
@@ -74,8 +74,7 @@ css::uno::Reference< XTablesSupplier > ODbaseConnection::createCatalog()
     Reference< XTablesSupplier > xTab = m_xCatalog;
     if(!xTab.is())
     {
-        ODbaseCatalog *pCat = new ODbaseCatalog(this);
-        xTab = pCat;
+        xTab = new ODbaseCatalog(this);
         m_xCatalog = xTab;
     }
     return xTab;
@@ -97,9 +96,7 @@ Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareStatement( con
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
-
-    ODbasePreparedStatement* pStmt = new ODbasePreparedStatement(this);
-    Reference< XPreparedStatement > xHoldAlive = pStmt;
+    rtl::Reference<ODbasePreparedStatement> pStmt = new ODbasePreparedStatement(this);
     pStmt->construct(sql);
     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
     return pStmt;
diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx
index b896e942cb01..cb8113a52652 100644
--- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx
@@ -56,8 +56,7 @@ Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw(  )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
 
     static ODatabaseMetaDataResultSet::ORows aRows;
     if(aRows.empty())
@@ -148,7 +147,7 @@ Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw(  )
     }
 
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns(
@@ -244,11 +243,10 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns(
             throw aSql;
         throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
     }
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo(
@@ -316,10 +314,9 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo(
         }
     }
 
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo);
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 OUString SAL_CALL ODbaseDatabaseMetaData::getURL(  )
diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx
index 5d9d56dcd5cf..8e571a04e98e 100644
--- a/connectivity/source/drivers/dbase/DDriver.cxx
+++ b/connectivity/source/drivers/dbase/DDriver.cxx
@@ -64,12 +64,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const S
     if ( ! acceptsURL(url) )
         return nullptr;
 
-    ODbaseConnection* pCon = new ODbaseConnection(this);
+    rtl::Reference<ODbaseConnection> pCon = new ODbaseConnection(this);
     pCon->construct(url,info);
-    Reference< XConnection > xCon = pCon;
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx
index 1ebce2612098..2a4cf72fb496 100644
--- a/connectivity/source/drivers/dbase/DIndexes.cxx
+++ b/connectivity/source/drivers/dbase/DIndexes.cxx
@@ -63,7 +63,7 @@ sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName)
         ReadHeader(*pFileStream, aHeader);
         pFileStream.reset();
 
-        ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
+        rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName);
         xRet = pIndex;
         pIndex->openIndexFile();
     }
diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 113fc5b5c41d..7a571a44b6ef 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -2154,7 +2154,7 @@ void ODbaseTable::alterColumn(sal_Int32 index,
 
         OUString sTempName = createTempFile();
 
-        ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection));
+        rtl::Reference<ODbaseTable> pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection));
         Reference<XPropertySet> xHoldTable = pNewTable;
         pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName));
         Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY);
@@ -2205,7 +2205,7 @@ void ODbaseTable::alterColumn(sal_Int32 index,
         pNewTable->construct();
 
         // copy the data
-        copyData(pNewTable,0);
+        copyData(pNewTable.get(),0);
 
         // now drop the old one
         if( DropImpl() ) // we don't want to delete the memo columns too
diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx
index 1d922969493f..74c81c62601b 100644
--- a/connectivity/source/drivers/dbase/DTables.cxx
+++ b/connectivity/source/drivers/dbase/DTables.cxx
@@ -45,12 +45,11 @@ using namespace ::com::sun::star::container;
 
 sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName)
 {
-    ODbaseTable* pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
+    rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
                                         _rName,"TABLE");
 
-    sdbcx::ObjectType xRet = pRet;
     pRet->construct();
-    return xRet;
+    return pRet;
 }
 
 void ODbaseTables::impl_refresh(  )
diff --git a/connectivity/source/drivers/file/FColumns.cxx b/connectivity/source/drivers/file/FColumns.cxx
index e703112f71c4..1b90385bf9c0 100644
--- a/connectivity/source/drivers/file/FColumns.cxx
+++ b/connectivity/source/drivers/file/FColumns.cxx
@@ -48,7 +48,7 @@ sdbcx::ObjectType OColumns::createObject(const OUString& _rName)
         {
             if(xRow->getString(4) == _rName)
             {
-                sdbcx::OColumn* pRet = new sdbcx::OColumn(_rName,
+                xRet = new sdbcx::OColumn(_rName,
                                             xRow->getString(6),
                                             xRow->getString(13),
                                             xRow->getString(12),
@@ -63,7 +63,6 @@ sdbcx::ObjectType OColumns::createObject(const OUString& _rName)
                                             sCatalogName,
                                             sSchemaName,
                                             sTableName);
-                xRet = pRet;
                 break;
             }
         }
diff --git a/connectivity/source/drivers/file/FConnection.cxx b/connectivity/source/drivers/file/FConnection.cxx
index 5c56ce4d5e5d..964d8ff16861 100644
--- a/connectivity/source/drivers/file/FConnection.cxx
+++ b/connectivity/source/drivers/file/FConnection.cxx
@@ -229,8 +229,7 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OU
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
 
-    OPreparedStatement* pStmt = new OPreparedStatement(this);
-    Reference< XPreparedStatement > xHoldAlive = pStmt;
+    rtl::Reference<OPreparedStatement> pStmt = new OPreparedStatement(this);
     pStmt->construct(sql);
     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
     return pStmt;
diff --git a/connectivity/source/drivers/file/FDatabaseMetaData.cxx b/connectivity/source/drivers/file/FDatabaseMetaData.cxx
index 2fffb76f78e3..aa24ef836f15 100644
--- a/connectivity/source/drivers/file/FDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/file/FDatabaseMetaData.cxx
@@ -158,9 +158,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTables );
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTables );
 
     // check if any type is given
     // when no types are given then we have to return all tables e.g. TABLE
@@ -185,7 +183,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
         }
     }
     if(!bTableFound)
-        return xRef;
+        return pResult;
 
     Reference<XDynamicResultSet> xContent = m_pConnection->getDir();
     Reference < XSortedDynamicResultSetFactory > xSRSFac =
@@ -302,7 +300,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
 
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength(  )
@@ -370,11 +368,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
     ODatabaseMetaDataResultSet::ORows aRows;
 
-
     Reference< XTablesSupplier > xTabSup = m_pConnection->createCatalog();
     if( xTabSup.is())
     {
@@ -424,7 +420,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
     }
 
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs(  )
@@ -616,8 +612,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes(  )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTableTypes );
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTableTypes );
     static ODatabaseMetaDataResultSet::ORows aRows;
     if(aRows.empty())
     {
@@ -627,7 +622,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes(  )
         aRows.push_back(aRow);
     }
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength(  )
diff --git a/connectivity/source/drivers/file/FDriver.cxx b/connectivity/source/drivers/file/FDriver.cxx
index 54be5f952429..f5045552cdb0 100644
--- a/connectivity/source/drivers/file/FDriver.cxx
+++ b/connectivity/source/drivers/file/FDriver.cxx
@@ -81,12 +81,11 @@ Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, con
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(ODriver_BASE::rBHelper.bDisposed);
 
-    OConnection* pCon = new OConnection(this);
-    Reference< XConnection > xCon = pCon;
+    rtl::Reference<OConnection> pCon = new OConnection(this);
     pCon->construct(url,info);
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 1abc21d9accc..7acaf03c2a1c 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -781,9 +781,8 @@ uno::Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection()
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes(  )
 {
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
         ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
 
     ODatabaseMetaDataResultSet::ORows aResults;
     ODatabaseMetaDataResultSet::ORow aRow(2);
@@ -803,7 +802,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes(  )
     aResults.push_back(aRow);
 
     pResultSet->setRows(aResults);
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
@@ -812,9 +811,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
 
     // this returns an empty resultset where the column-names are already set
     // in special the metadata of the resultset already returns the right columns
-    ODatabaseMetaDataResultSet* pResultSet =
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet =
             new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     static ODatabaseMetaDataResultSet::ORows aResults = []()
     {
         ODatabaseMetaDataResultSet::ORows tmp;
@@ -1029,7 +1027,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
         return tmp;
     }();
     pResultSet->setRows(aResults);
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
@@ -1042,9 +1040,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
              "Table: " << sTable
              << " & ColumnNamePattern: " << sColumnNamePattern);
 
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
         ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumnPrivileges);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     uno::Reference< XStatement > statement = m_pConnection->createStatement();
 
     static const char wld[] = "%";
@@ -1104,7 +1101,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
 
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
@@ -1308,12 +1305,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
 
         aResults.push_back(aCurrentRow);
     }
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
             ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumns);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
@@ -1325,9 +1321,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
     SAL_INFO("connectivity.firebird", "getTables() with "
              "TableNamePattern: " << tableNamePattern);
 
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
         ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     uno::Reference< XStatement > statement = m_pConnection->createStatement();
 
     static const char wld[] = "%";
@@ -1431,7 +1426,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
 
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns(
@@ -1477,9 +1472,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys(
 
 uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool bIsImport, std::u16string_view table )
 {
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
         ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eImportedKeys);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
 
     uno::Reference< XStatement > statement = m_pConnection->createStatement();
 
@@ -1559,7 +1553,7 @@ uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool bIsImport
     }
 
     pResultSet->setRows( aResults );
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
@@ -1610,12 +1604,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
 
         aResults.push_back(aCurrentRow);
     }
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
             ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo(
@@ -1704,12 +1697,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo(
 
         aResults.push_back(aCurrentRow);
     }
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
             ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier(
@@ -1729,9 +1721,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
     SAL_INFO("connectivity.firebird", "getTablePrivileges() with "
              "TableNamePattern: " << sTableNamePattern);
 
-    ODatabaseMetaDataResultSet* pResultSet = new
+    rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new
         ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTablePrivileges);
-    uno::Reference< XResultSet > xResultSet = pResultSet;
     uno::Reference< XStatement > statement = m_pConnection->createStatement();
 
     // TODO: column specific privileges are included, we may need
@@ -1785,7 +1776,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
 
     pResultSet->setRows( aResults );
 
-    return xResultSet;
+    return pResultSet;
 }
 
 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference(
diff --git a/connectivity/source/drivers/firebird/Driver.cxx b/connectivity/source/drivers/firebird/Driver.cxx
index 55e149e9de5c..c5886d25e5da 100644
--- a/connectivity/source/drivers/firebird/Driver.cxx
+++ b/connectivity/source/drivers/firebird/Driver.cxx
@@ -150,13 +150,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect(
     if ( ! acceptsURL(url) )
         return nullptr;
 
-    Connection* pCon = new Connection();
-    Reference< XConnection > xCon = pCon;
+    rtl::Reference<Connection> pCon = new Connection();
     pCon->construct(url, info);
 
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/flat/EConnection.cxx b/connectivity/source/drivers/flat/EConnection.cxx
index 5127d903cc6d..288a53fa649a 100644
--- a/connectivity/source/drivers/flat/EConnection.cxx
+++ b/connectivity/source/drivers/flat/EConnection.cxx
@@ -136,8 +136,7 @@ css::uno::Reference< XTablesSupplier > OFlatConnection::createCatalog()
     Reference< XTablesSupplier > xTab = m_xCatalog;
     if(!xTab.is())
     {
-        OFlatCatalog *pCat = new OFlatCatalog(this);
-        xTab = pCat;
+        xTab = new OFlatCatalog(this);
         m_xCatalog = xTab;
     }
     return xTab;
@@ -148,11 +147,9 @@ Reference< XStatement > SAL_CALL OFlatConnection::createStatement(  )
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(OConnection_B::rBHelper.bDisposed);
 
-    OFlatStatement* pStmt = new OFlatStatement(this);
-
-    Reference< XStatement > xStmt = pStmt;
+    rtl::Reference<OFlatStatement> pStmt = new OFlatStatement(this);
     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
-    return xStmt;
+    return pStmt;
 }
 
 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( const OUString& sql )
@@ -160,13 +157,10 @@ Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( cons
     ::osl::MutexGuard aGuard( m_aMutex );
     checkDisposed(OConnection_B::rBHelper.bDisposed);
 
-
-    OFlatPreparedStatement* pStmt = new OFlatPreparedStatement(this);
-    Reference< XPreparedStatement > xStmt = pStmt;
+    rtl::Reference<OFlatPreparedStatement> pStmt = new OFlatPreparedStatement(this);
     pStmt->construct(sql);
-
     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
-    return xStmt;
+    return pStmt;
 }
 
 Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareCall( const OUString& /*sql*/ )
diff --git a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx
index b69b34e363c3..5cb1a79a6c2c 100644
--- a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx
@@ -49,8 +49,7 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw(  )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
 
     static ODatabaseMetaDataResultSet::ORows aRows = [&]()
     {
@@ -142,7 +141,7 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw(  )
     }();
 
     pResult->setRows(aRows);
-    return xRef;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns(
@@ -228,11 +227,10 @@ Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns(
         }
     }
 
-    ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 OUString SAL_CALL OFlatDatabaseMetaData::getURL(  )
diff --git a/connectivity/source/drivers/flat/EDriver.cxx b/connectivity/source/drivers/flat/EDriver.cxx
index bdd8bfa202a9..3e6bb90a7ed6 100644
--- a/connectivity/source/drivers/flat/EDriver.cxx
+++ b/connectivity/source/drivers/flat/EDriver.cxx
@@ -66,12 +66,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const S
     if ( ! acceptsURL(url) )
         return nullptr;
 
-    OFlatConnection* pCon = new OFlatConnection(this);
+    rtl::Reference<OFlatConnection> pCon = new OFlatConnection(this);
     pCon->construct(url,info);
-    Reference< XConnection > xCon = pCon;
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx
index fa4305e991a4..2a7bd3d26362 100644
--- a/connectivity/source/drivers/flat/ETable.cxx
+++ b/connectivity/source/drivers/flat/ETable.cxx
@@ -176,7 +176,7 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale)
             aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase);
         }
 
-        sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias,aTypeNames[i],OUString(),OUString(),
+        rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn(aAlias,aTypeNames[i],OUString(),OUString(),
                                                 ColumnValue::NULLABLE,
                                                 m_aPrecisions[i],
                                                 m_aScales[i],
@@ -186,8 +186,7 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale)
                                                 false,
                                                 bCase,
                                                 m_CatalogName, getSchema(), getName());
-        Reference< XPropertySet> xCol = pColumn;
-        m_aColumns->push_back(xCol);
+        m_aColumns->push_back(pColumn);
     }
 
     m_pFileStream->Seek(m_aRowPosToFilePos[0].second);
diff --git a/connectivity/source/drivers/flat/ETables.cxx b/connectivity/source/drivers/flat/ETables.cxx
index 81f366a9e7d0..2e4dd377ed83 100644
--- a/connectivity/source/drivers/flat/ETables.cxx
+++ b/connectivity/source/drivers/flat/ETables.cxx
@@ -34,11 +34,10 @@ using namespace ::com::sun::star::container;
 
 sdbcx::ObjectType OFlatTables::createObject(const OUString& _rName)
 {
-    OFlatTable* pRet = new OFlatTable(this, static_cast<OFlatConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
+    rtl::Reference<OFlatTable> pRet = new OFlatTable(this, static_cast<OFlatConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()),
                                         _rName,"TABLE");
-    sdbcx::ObjectType xRet = pRet;
     pRet->construct();
-    return xRet;
+    return pRet;
 }
 
 
diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 6ff0f539407b..b34256d2d34b 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -346,7 +346,7 @@ namespace connectivity
                     {
                         Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext );
 
-                        auto tmp = new OConnectionController(this);
+                        rtl::Reference<OConnectionController> tmp = new OConnectionController(this);
                         xDesktop->addTerminateListener(tmp);
                         return tmp;
                     }();
diff --git a/connectivity/source/drivers/hsqldb/HTable.cxx b/connectivity/source/drivers/hsqldb/HTable.cxx
index 0049ff919fc3..89d75fac7e3d 100644
--- a/connectivity/source/drivers/hsqldb/HTable.cxx
+++ b/connectivity/source/drivers/hsqldb/HTable.cxx
@@ -260,12 +260,11 @@ void OHSQLTable::alterColumnType(sal_Int32 nNewType,const OUString& _rColName, c
     (void)_rColName;
 #endif
 
-    OHSQLColumn* pColumn = new OHSQLColumn;
-    Reference<XPropertySet> xProp = pColumn;
-    ::comphelper::copyProperties(_xDescriptor,xProp);
-    xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType));
+    rtl::Reference<OHSQLColumn> pColumn = new OHSQLColumn;
+    ::comphelper::copyProperties(_xDescriptor,pColumn);
+    pColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType));
 
-    sSql += ::dbtools::createStandardColumnPart(xProp,getConnection());
+    sSql += ::dbtools::createStandardColumnPart(pColumn,getConnection());
     executeStatement(sSql);
 }
 
diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx
index 787af894b992..472b8b514942 100644
--- a/connectivity/source/drivers/hsqldb/HTables.cxx
+++ b/connectivity/source/drivers/hsqldb/HTables.cxx
@@ -66,7 +66,7 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName)
                 nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP );
 
             // obtain privileges
-            OHSQLTable* pRet = new OHSQLTable( this
+            xRet = new OHSQLTable( this
                                                 ,static_cast<OHCatalog&>(m_rParent).getConnection()
                                                 ,sTable
                                                 ,xRow->getString(4)
@@ -74,7 +74,6 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName)
                                                 ,sSchema
                                                 ,sCatalog
                                                 ,nPrivileges);
-            xRet = pRet;
         }
         ::comphelper::disposeComponent(xResult);
     }
diff --git a/connectivity/source/drivers/hsqldb/HUsers.cxx b/connectivity/source/drivers/hsqldb/HUsers.cxx
index 40d1f5243cb6..9fe31e58eb01 100644
--- a/connectivity/source/drivers/hsqldb/HUsers.cxx
+++ b/connectivity/source/drivers/hsqldb/HUsers.cxx
@@ -57,8 +57,7 @@ void OUsers::impl_refresh()
 
 Reference< XPropertySet > OUsers::createDescriptor()
 {
-    OUserExtend* pNew = new OUserExtend(m_xConnection);
-    return pNew;
+    return new OUserExtend(m_xConnection);
 }
 
 // XAppend
diff --git a/connectivity/source/drivers/hsqldb/HViews.cxx b/connectivity/source/drivers/hsqldb/HViews.cxx
index e67a9fa14f86..1f4b807484e5 100644
--- a/connectivity/source/drivers/hsqldb/HViews.cxx
+++ b/connectivity/source/drivers/hsqldb/HViews.cxx
@@ -78,8 +78,7 @@ void HViews::disposing()
 Reference< XPropertySet > HViews::createDescriptor()
 {
     Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
-    connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
-    return pNew;
+    return new connectivity::sdbcx::OView(true, xConnection->getMetaData());
 }
 
 // XAppend
diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx
index b14c1372c9a3..39bacf0e3d2c 100644
--- a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx
@@ -460,7 +460,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges(
 
                 }
                 // fill our own resultset
-                ODatabaseMetaDataResultSet* pNewPrivRes = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
+                rtl::Reference<ODatabaseMetaDataResultSet> pNewPrivRes = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
                 Reference< XResultSet > xTemp = xReturn;
                 xReturn = pNewPrivRes;
                 ODatabaseMetaDataResultSet::ORows aRows;
diff --git a/connectivity/source/drivers/jdbc/JConnection.cxx b/connectivity/source/drivers/jdbc/JConnection.cxx
index e3cd11cabb90..0529979e2b5b 100644
--- a/connectivity/source/drivers/jdbc/JConnection.cxx
+++ b/connectivity/source/drivers/jdbc/JConnection.cxx
@@ -436,7 +436,7 @@ Reference< XStatement > SAL_CALL java_sql_Connection::createStatement(  )
     m_aLogger.log( LogLevel::FINE, STR_LOG_CREATE_STATEMENT );
 
     SDBThreadAttach t;
-    java_sql_Statement* pStatement = new java_sql_Statement( t.pEnv, *this );
+    rtl::Reference<java_sql_Statement> pStatement = new java_sql_Statement( t.pEnv, *this );
     Reference< XStatement > xStmt = pStatement;
     m_aStatements.push_back( WeakReferenceHelper( xStmt ) );
 
@@ -452,7 +452,7 @@ Reference< XPreparedStatement > SAL_CALL java_sql_Connection::prepareStatement(
 
     SDBThreadAttach t;
 
-    java_sql_PreparedStatement* pStatement = new java_sql_PreparedStatement( t.pEnv, *this, sql );
+    rtl::Reference<java_sql_PreparedStatement> pStatement = new java_sql_PreparedStatement( t.pEnv, *this, sql );
     Reference< XPreparedStatement > xReturn( pStatement );
     m_aStatements.push_back(WeakReferenceHelper(xReturn));
 
@@ -468,7 +468,7 @@ Reference< XPreparedStatement > SAL_CALL java_sql_Connection::prepareCall( const
 
     SDBThreadAttach t;
 
-    java_sql_CallableStatement* pStatement = new java_sql_CallableStatement( t.pEnv, *this, sql );
+    rtl::Reference<java_sql_CallableStatement> pStatement = new java_sql_CallableStatement( t.pEnv, *this, sql );
     Reference< XPreparedStatement > xStmt( pStatement );
     m_aStatements.push_back(WeakReferenceHelper(xStmt));
 
diff --git a/connectivity/source/drivers/jdbc/JDriver.cxx b/connectivity/source/drivers/jdbc/JDriver.cxx
index 1d5424389ce7..62d997540485 100644
--- a/connectivity/source/drivers/jdbc/JDriver.cxx
+++ b/connectivity/source/drivers/jdbc/JDriver.cxx
@@ -71,7 +71,7 @@ Reference< XConnection > SAL_CALL java_sql_Driver::connect( const OUString& url,
     Reference< XConnection > xOut;
     if ( acceptsURL(url ) )
     {
-        java_sql_Connection* pConnection = new java_sql_Connection( *this );
+        rtl::Reference<java_sql_Connection> pConnection = new java_sql_Connection( *this );
         xOut = pConnection;
         if ( !pConnection->construct(url,info) )
             xOut.clear(); // an error occurred and the java driver didn't throw an exception
diff --git a/connectivity/source/drivers/mysql_jdbc/YTable.cxx b/connectivity/source/drivers/mysql_jdbc/YTable.cxx
index 374825d32abb..7e08f896fddb 100644
--- a/connectivity/source/drivers/mysql_jdbc/YTable.cxx
+++ b/connectivity/source/drivers/mysql_jdbc/YTable.cxx
@@ -268,14 +268,13 @@ void OMySQLTable::alterColumnType(sal_Int32 nNewType, const OUString& _rColName,
     OUString sSql
         = getAlterTableColumnPart() + " CHANGE " + ::dbtools::quoteName(sQuote, _rColName) + " ";
 
-    OColumn* pColumn = new OColumn(true);
-    Reference<XPropertySet> xProp = pColumn;
-    ::comphelper::copyProperties(_xDescriptor, xProp);
-    xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),
-                            makeAny(nNewType));
+    rtl::Reference<OColumn> pColumn = new OColumn(true);
+    ::comphelper::copyProperties(_xDescriptor, pColumn);
+    pColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),
+                              makeAny(nNewType));
 
     sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart(
-        xProp, getConnection(), static_cast<OTables*>(m_pTables), getTypeCreatePattern()));
+        pColumn, getConnection(), static_cast<OTables*>(m_pTables), getTypeCreatePattern()));
     executeStatement(sSql);
 }
 
diff --git a/connectivity/source/drivers/mysql_jdbc/YTables.cxx b/connectivity/source/drivers/mysql_jdbc/YTables.cxx
index e21e05fb2914..a5a023808edd 100644
--- a/connectivity/source/drivers/mysql_jdbc/YTables.cxx
+++ b/connectivity/source/drivers/mysql_jdbc/YTables.cxx
@@ -67,10 +67,9 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName)
                                           | Privilege::UPDATE | Privilege::INSERT
                                           | Privilege::SELECT;
 
-            OMySQLTable* pRet = new OMySQLTable(
-                this, static_cast<OMySQLCatalog&>(m_rParent).getConnection(), sTable,
-                xRow->getString(4), xRow->getString(5), sSchema, sCatalog, nPrivileges);
-            xRet = pRet;
+            xRet = new OMySQLTable(this, static_cast<OMySQLCatalog&>(m_rParent).getConnection(),
+                                   sTable, xRow->getString(4), xRow->getString(5), sSchema,
+                                   sCatalog, nPrivileges);
         }
         ::comphelper::disposeComponent(xResult);
     }
diff --git a/connectivity/source/drivers/mysql_jdbc/YUsers.cxx b/connectivity/source/drivers/mysql_jdbc/YUsers.cxx
index 17fc788179c1..ed33cb0e2d7c 100644
--- a/connectivity/source/drivers/mysql_jdbc/YUsers.cxx
+++ b/connectivity/source/drivers/mysql_jdbc/YUsers.cxx
@@ -50,11 +50,7 @@ sdbcx::ObjectType OUsers::createObject(const OUString& _rName)
 
 void OUsers::impl_refresh() { m_pParent->refreshUsers(); }
 
-Reference<XPropertySet> OUsers::createDescriptor()
-{
-    OUserExtend* pNew = new OUserExtend(m_xConnection);
-    return pNew;
-}
+Reference<XPropertySet> OUsers::createDescriptor() { return new OUserExtend(m_xConnection); }
 
 // XAppend
 sdbcx::ObjectType OUsers::appendObject(const OUString& _rForName,
diff --git a/connectivity/source/drivers/mysql_jdbc/YViews.cxx b/connectivity/source/drivers/mysql_jdbc/YViews.cxx
index 4bdeca9596b3..3dba721c0c86 100644
--- a/connectivity/source/drivers/mysql_jdbc/YViews.cxx
+++ b/connectivity/source/drivers/mysql_jdbc/YViews.cxx
@@ -59,7 +59,7 @@ void OViews::disposing()
 Reference<XPropertySet> OViews::createDescriptor()
 {
     Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
-    connectivity::sdbcx::OView* pNew
+    rtl::Reference<connectivity::sdbcx::OView> pNew
         = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
     return pNew;
 }
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx b/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx
index c7c88d03ebe6..6e4f3d9050d3 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx
@@ -86,12 +86,11 @@ Reference<XConnection> SAL_CALL MysqlCDriver::connect(const OUString& url,
 
     Reference<XConnection> xConn;
     // create a new connection with the given properties and append it to our vector
-    OConnection* pCon = new OConnection(*this);
-    xConn = pCon;
+    rtl::Reference<OConnection> pCon = new OConnection(*this);
 
     pCon->construct(url, info);
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
-    return xConn;
+    return pCon;
 }
 
 sal_Bool SAL_CALL MysqlCDriver::acceptsURL(const OUString& url)
diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
index c9ed165a8c26..957142027182 100644
--- a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
+++ b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx
@@ -65,7 +65,7 @@ Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw(  )
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openTypeInfo();
     }
@@ -88,7 +88,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs(  )
     {
         try
         {
-            ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+            rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
             xRef = pResult;
             pResult->openCatalogs();
         }
@@ -115,7 +115,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas(  )
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openSchemas();
     }
@@ -133,7 +133,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openColumnPrivileges(m_bUseCatalog ? catalog : Any(),schema,table,columnNamePattern);
     }
@@ -151,7 +151,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,columnNamePattern);
     }
@@ -169,7 +169,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openTables(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,types);
     }
@@ -187,7 +187,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openProcedureColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern,columnNamePattern);
     }
@@ -205,7 +205,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openProcedures(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern);
     }
@@ -225,7 +225,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns(
     {
         if ( !m_pConnection->preventGetVersionColumns() )
         {
-            ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+            rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
             xRef = pResult;
             pResult->openVersionColumns(m_bUseCatalog ? catalog : Any(),schema,table);
             bSuccess = true;
@@ -333,7 +333,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openExportedKeys(m_bUseCatalog ? catalog : Any(),schema,table);
     }
@@ -350,7 +350,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openImportedKeys(m_bUseCatalog ? catalog : Any(),schema,table);
     }
@@ -367,7 +367,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openPrimaryKeys(m_bUseCatalog ? catalog : Any(),schema,table);
     }
@@ -385,7 +385,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openIndexInfo(m_bUseCatalog ? catalog : Any(),schema,table,unique,approximate);
     }
@@ -403,7 +403,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openBestRowIdentifier(m_bUseCatalog ? catalog : Any(),schema,table,scope,nullable);
     }
@@ -421,10 +421,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
     {
         return new OResultSetPrivileges(this,catalog,schemaPattern,tableNamePattern);
     }
-    ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
-    Reference< XResultSet > xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
     pResult->openTablePrivileges(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern);
-    return xRef;
+    return pResult;
 }
 
 Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference(
@@ -435,7 +434,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference(
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openForeignKeys(m_bUseCatalog ? primaryCatalog : Any(),primarySchema.toChar() == '%' ? &primarySchema : nullptr,&primaryTable,
             m_bUseCatalog ? foreignCatalog : Any(), foreignSchema.toChar() == '%' ? &foreignSchema : nullptr,&foreignTable);
@@ -718,7 +717,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes(  )
     Reference< XResultSet > xRef;
     try
     {
-        ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection);
+        rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection);
         xRef = pResult;
         pResult->openTablesTypes();
     }
diff --git a/connectivity/source/drivers/odbc/ODriver.cxx b/connectivity/source/drivers/odbc/ODriver.cxx
index b4318d43b18b..5bdd9e5d0461 100644
--- a/connectivity/source/drivers/odbc/ODriver.cxx
+++ b/connectivity/source/drivers/odbc/ODriver.cxx
@@ -87,12 +87,11 @@ Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, cons
         if(!EnvironmentHandle(aPath))
             throw SQLException(aPath,*this,OUString(),1000,Any());
     }
-    OConnection* pCon = new OConnection(m_pDriverHandle,this);
-    Reference< XConnection > xCon = pCon;
+    rtl::Reference<OConnection> pCon = new OConnection(m_pDriverHandle,this);
     pCon->Construct(url,info);
     m_xConnections.push_back(WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url )
diff --git a/connectivity/source/drivers/odbc/OPreparedStatement.cxx b/connectivity/source/drivers/odbc/OPreparedStatement.cxx
index b404549ce495..ce04972ce1bd 100644
--- a/connectivity/source/drivers/odbc/OPreparedStatement.cxx
+++ b/connectivity/source/drivers/odbc/OPreparedStatement.cxx
@@ -914,9 +914,9 @@ void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex)
     }
 }
 
-OResultSet* OPreparedStatement::createResultSet()
+rtl::Reference<OResultSet> OPreparedStatement::createResultSet()
 {
-    OResultSet* pReturn = new OResultSet(m_aStatementHandle,this);
+    rtl::Reference<OResultSet> pReturn = new OResultSet(m_aStatementHandle,this);
     pReturn->setMetaData(getMetaData());
     return pReturn;
 }
diff --git a/connectivity/source/drivers/odbc/OStatement.cxx b/connectivity/source/drivers/odbc/OStatement.cxx
index 2ff607be5aa9..69f2f74783c2 100644
--- a/connectivity/source/drivers/odbc/OStatement.cxx
+++ b/connectivity/source/drivers/odbc/OStatement.cxx
@@ -372,7 +372,7 @@ Reference< XResultSet > OStatement_Base::getResultSet(bool checkCount)
         ::dbtools::throwFunctionSequenceException(*this);
     }
 
-    OResultSet* pRs = nullptr;
+    rtl::Reference<OResultSet> pRs;
     sal_Int32 numCols = 1;
 
     // If we already know we have result columns, checkCount
@@ -1063,7 +1063,7 @@ void SAL_CALL OStatement::release() throw()
     OStatement_BASE2::release();
 }
 
-OResultSet* OStatement_Base::createResultSet()
+rtl::Reference<OResultSet> OStatement_Base::createResultSet()
 {
     return new OResultSet(m_aStatementHandle,this);
 }
diff --git a/connectivity/source/drivers/writer/WConnection.cxx b/connectivity/source/drivers/writer/WConnection.cxx
index c4cc699e4ad2..d8fd10302e00 100644
--- a/connectivity/source/drivers/writer/WConnection.cxx
+++ b/connectivity/source/drivers/writer/WConnection.cxx
@@ -203,8 +203,7 @@ css::uno::Reference<css::sdbcx::XTablesSupplier> OWriterConnection::createCatalo
     uno::Reference<css::sdbcx::XTablesSupplier> xTab = m_xCatalog;
     if (!xTab.is())
     {
-        auto pCat = new OWriterCatalog(this);
-        xTab = pCat;
+        xTab = new OWriterCatalog(this);
         m_xCatalog = xTab;
     }
     return xTab;
@@ -226,8 +225,8 @@ uno::Reference<sdbc::XPreparedStatement>
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
 
-    auto pStmt = new component::OComponentPreparedStatement(this);
-    uno::Reference<sdbc::XPreparedStatement> xHoldAlive = pStmt;
+    rtl::Reference<component::OComponentPreparedStatement> pStmt
+        = new component::OComponentPreparedStatement(this);
     pStmt->construct(sql);
     m_aStatements.push_back(uno::WeakReferenceHelper(*pStmt));
     return pStmt;
diff --git a/connectivity/source/drivers/writer/WDatabaseMetaData.cxx b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx
index 2e55a46d2c6d..99c81b7c2840 100644
--- a/connectivity/source/drivers/writer/WDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx
@@ -47,8 +47,8 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables(
 {
     ::osl::MutexGuard aGuard(m_aMutex);
 
-    auto pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
-    uno::Reference<sdbc::XResultSet> xRef = pResult;
+    rtl::Reference<ODatabaseMetaDataResultSet> pResult
+        = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
 
     // check if ORowSetValue type is given
     // when no types are given then we have to return all tables e.g. TABLE
@@ -73,7 +73,7 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables(
         }
     }
     if (!bTableFound)
-        return xRef;
+        return pResult;
 
     // get the table names from the document
 
@@ -104,7 +104,7 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables(
 
     pResult->setRows(aRows);
 
-    return xRef;
+    return pResult;
 }
 
 } // namespace
diff --git a/connectivity/source/drivers/writer/WDriver.cxx b/connectivity/source/drivers/writer/WDriver.cxx
index 9bd3bc76c1e8..7c8cde2da3b7 100644
--- a/connectivity/source/drivers/writer/WDriver.cxx
+++ b/connectivity/source/drivers/writer/WDriver.cxx
@@ -61,12 +61,11 @@ uno::Reference<sdbc::XConnection>
     if (!acceptsURL(url))
         return nullptr;
 
-    auto pCon = new OWriterConnection(this);
+    rtl::Reference<OWriterConnection> pCon = new OWriterConnection(this);
     pCon->construct(url, info);
-    uno::Reference<sdbc::XConnection> xCon = pCon;
     m_xConnections.push_back(uno::WeakReferenceHelper(*pCon));
 
-    return xCon;
+    return pCon;
 }
 
 sal_Bool SAL_CALL ODriver::acceptsURL(const OUString& url)
diff --git a/connectivity/source/drivers/writer/WTable.cxx b/connectivity/source/drivers/writer/WTable.cxx
index 7236df2476dd..8448132556e6 100644
--- a/connectivity/source/drivers/writer/WTable.cxx
+++ b/connectivity/source/drivers/writer/WTable.cxx
@@ -159,12 +159,11 @@ void OWriterTable::fillColumns()
             aFind = connectivity::find(m_aColumns->begin(), m_aColumns->end(), aAlias, aCase);
         }
 
-        auto pColumn = new sdbcx::OColumn(
+        rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn(
             aAlias, aTypeName, OUString(), OUString(), sdbc::ColumnValue::NULLABLE, nPrecision,
             nDecimals, eType, false, false, bCurrency, bStoresMixedCaseQuotedIdentifiers,
             m_CatalogName, getSchema(), getName());
-        uno::Reference<XPropertySet> xCol = pColumn;
-        m_aColumns->push_back(xCol);
+        m_aColumns->push_back(pColumn);
     }
 }
 
diff --git a/connectivity/source/drivers/writer/WTables.cxx b/connectivity/source/drivers/writer/WTables.cxx
index 15dc9e0c1941..8b2692d93a01 100644
--- a/connectivity/source/drivers/writer/WTables.cxx
+++ b/connectivity/source/drivers/writer/WTables.cxx
@@ -31,13 +31,13 @@ namespace connectivity::writer
 {
 sdbcx::ObjectType OWriterTables::createObject(const OUString& rName)
 {
-    auto pTable = new OWriterTable(this,
-                                   static_cast<OWriterConnection*>(
-                                       static_cast<file::OFileCatalog&>(m_rParent).getConnection()),
-                                   rName, "TABLE");
-    sdbcx::ObjectType xRet = pTable;
+    rtl::Reference<OWriterTable> pTable
+        = new OWriterTable(this,
+                           static_cast<OWriterConnection*>(
+                               static_cast<file::OFileCatalog&>(m_rParent).getConnection()),
+                           rName, "TABLE");
     pTable->construct();
-    return xRet;
+    return pTable;
 }
 
 } // namespace
diff --git a/connectivity/source/inc/odbc/OPreparedStatement.hxx b/connectivity/source/inc/odbc/OPreparedStatement.hxx
index 1197c1be8544..a93b958be79a 100644
--- a/connectivity/source/inc/odbc/OPreparedStatement.hxx
+++ b/connectivity/source/inc/odbc/OPreparedStatement.hxx
@@ -82,7 +82,7 @@ namespace connectivity::odbc
             /**
                 creates the driver specific resultset (factory)
             */
-            virtual OResultSet* createResultSet() override;
+            virtual rtl::Reference<OResultSet> createResultSet() override;
 
             virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,
                                                                    const css::uno::Any& rValue) override;
diff --git a/connectivity/source/inc/odbc/OStatement.hxx b/connectivity/source/inc/odbc/OStatement.hxx
index e0d1bde55587..9d4baa6fc7da 100644
--- a/connectivity/source/inc/odbc/OStatement.hxx
+++ b/connectivity/source/inc/odbc/OStatement.hxx
@@ -127,7 +127,7 @@ namespace connectivity::odbc
             /**
                 creates the driver specific resultset (factory)
             */
-            virtual OResultSet* createResultSet();
+            virtual rtl::Reference<OResultSet> createResultSet();
 
             /// @throws css::sdbc::SQLException
             /// @throws css::uno::RuntimeException
diff --git a/connectivity/source/parse/PColumn.cxx b/connectivity/source/parse/PColumn.cxx
index cf9b17ee51df..5ada4136cc93 100644
--- a/connectivity/source/parse/PColumn.cxx
+++ b/connectivity/source/parse/PColumn.cxx
@@ -109,7 +109,7 @@ OParseColumn::OParseColumn( const OUString& Name,
     StringMap aColumnMap;
     for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
     {
-        OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
+        rtl::Reference<OParseColumn> pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
         aReturn->push_back( pColumn );
         if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
         {
@@ -125,7 +125,7 @@ OParseColumn::OParseColumn( const OUString& Name,
 }
 
 
-OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
+rtl::Reference<OParseColumn> OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
     const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
 {
     OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
@@ -142,7 +142,7 @@ OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSe
         sLabel = sAlias;
     }
     _rColumns.emplace(sLabel,0);
-    OParseColumn* pColumn = new OParseColumn(
+    rtl::Reference<OParseColumn> pColumn = new OParseColumn(
         sLabel,
         _rxResMetaData->getColumnTypeName( _nColumnPos ),
         OUString(),
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 766dcf3b8198..e6e3e1c72535 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -820,14 +820,14 @@ void OSQLParseTreeIterator::traverseCreateColumns(const OSQLParseNode* pSelectNo
             if (!aTypeName.isEmpty())
             {
                 //TODO:Create a new class for create statement to handle field length
-                OParseColumn* pColumn = new OParseColumn(aColumnName,aTypeName,OUString(),OUString(),
+                rtl::Reference<OParseColumn> pColumn = new OParseColumn(aColumnName,aTypeName,OUString(),OUString(),
                     ColumnValue::NULLABLE_UNKNOWN,0,0,nType,false,false,isCaseSensitive(),
                     OUString(),OUString(),OUString());
                 pColumn->setFunction(false);
                 pColumn->setRealName(aColumnName);
 
                 Reference< XPropertySet> xCol = pColumn;
-                m_aCreateColumns->push_back(xCol);
+                m_aCreateColumns->push_back(pColumn);
             }
         }
 
@@ -1344,7 +1344,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode
         }
         sal_Int32 nType = ::connectivity::OSQLParser::getFunctionParameterType( _pParentNode->getChild(0)->getTokenID(), i-1);
 
-        OParseColumn* pColumn = new OParseColumn(   sParameterName,
+        rtl::Reference<OParseColumn> pColumn = new OParseColumn(   sParameterName,
                                                     OUString(),
                                                     OUString(),
                                                     OUString(),
@@ -1373,7 +1373,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode
         );
         if(aIter != m_aSelectColumns->end())
         {
-            OParseColumn* pNewColumn = new OParseColumn(*aIter,isCaseSensitive());
+            rtl::Reference<OParseColumn> pNewColumn = new OParseColumn(*aIter,isCaseSensitive());
             pNewColumn->setName(sParameterName);
             pNewColumn->setRealName(_aColumnName);
             m_aParameters->push_back(pNewColumn);
@@ -1386,7 +1386,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode
 
             if ( xColumn.is() )
             {
-                OParseColumn* pNewColumn = new OParseColumn(xColumn,isCaseSensitive());
+                rtl::Reference<OParseColumn> pNewColumn = new OParseColumn(xColumn,isCaseSensitive());
                 pNewColumn->setName(sParameterName);
                 pNewColumn->setRealName(_aColumnName);
                 m_aParameters->push_back(pNewColumn);
@@ -1411,7 +1411,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode
 
             OUString aNewColName( getUniqueColumnName( sParameterName ) );
 
-            OParseColumn* pColumn = new OParseColumn(aNewColName,
+            rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,
                                                     OUString(),
                                                     OUString(),
                                                     OUString(),
@@ -1546,7 +1546,7 @@ void OSQLParseTreeIterator::appendColumns(::rtl::Reference<OSQLColumns> const &
         Reference< XPropertySet > xColumn;
         if(xColumns->hasByName(*pBegin) && (xColumns->getByName(*pBegin) >>= xColumn) && xColumn.is())
         {
-            OParseColumn* pColumn = new OParseColumn(aName
+            rtl::Reference<OParseColumn> pColumn = new OParseColumn(aName
                                                 ,   getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
                                                 ,   getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
                                                 ,   getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
@@ -1563,8 +1563,7 @@ void OSQLParseTreeIterator::appendColumns(::rtl::Reference<OSQLColumns> const &
 
             pColumn->setTableName(_rTableAlias);
             pColumn->setRealName(*pBegin);
-            Reference< XPropertySet> xCol = pColumn;
-            _rColumns->push_back(xCol);
+            _rColumns->push_back(pColumn);
         }
         else
             impl_appendError( IParseContext::ErrorCode::InvalidColumn, pBegin, &_rTableAlias );
@@ -1608,7 +1607,7 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
 
                 OUString aNewColName(getUniqueColumnName(rColumnAlias));
 
-                OParseColumn* pColumn = new OParseColumn(xColumn,isCaseSensitive());
+                rtl::Reference<OParseColumn> pColumn = new OParseColumn(xColumn,isCaseSensitive());
                 xNewColumn = pColumn;
                 pColumn->setTableName(table.first);
                 pColumn->setName(aNewColName);
@@ -1623,7 +1622,7 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
                 // => assume an expression
                 OUString aNewColName( getUniqueColumnName( rColumnAlias ) );
                 // did not find a column with this name in any of the tables
-                OParseColumn* pColumn = new OParseColumn(
+                rtl::Reference<OParseColumn> pColumn = new OParseColumn(
                     aNewColName,
                     "VARCHAR",
                         // TODO: does this match with _nType?
@@ -1652,15 +1651,14 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
         {
             OUString aNewColName(getUniqueColumnName(rColumnAlias));
 
-            OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
+            rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
                 ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,false,false,isCaseSensitive(),
                 OUString(),OUString(),OUString());
             pColumn->setFunction(true);
             pColumn->setAggregateFunction(bAggFkt);
             pColumn->setRealName(rColumnName);
 
-            Reference< XPropertySet> xCol = pColumn;
-            _rColumns->push_back(xCol);
+            _rColumns->push_back(pColumn);
         }
     }
     else    // ColumnName and TableName exist
@@ -1674,7 +1672,7 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
             {
                 OUString aNewColName(getUniqueColumnName(rColumnAlias));
 
-                OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
+                rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
                     ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,false,false,isCaseSensitive(),
                     OUString(),OUString(),OUString());
                 pColumn->setFunction(true);
@@ -1684,8 +1682,7 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
                 assert(false);
                 pColumn->setTableName(aFind->first);
 
-                Reference< XPropertySet> xCol = pColumn;
-                _rColumns->push_back(xCol);
+                _rColumns->push_back(pColumn);
             }
             else
             {
@@ -1694,13 +1691,12 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
                 {
                     OUString aNewColName(getUniqueColumnName(rColumnAlias));
 
-                    OParseColumn* pColumn = new OParseColumn(xColumn,isCaseSensitive());
+                    rtl::Reference<OParseColumn> pColumn = new OParseColumn(xColumn,isCaseSensitive());
                     pColumn->setName(aNewColName);
                     pColumn->setRealName(rColumnName);
                     pColumn->setTableName(aFind->first);
 
-                    Reference< XPropertySet> xCol = pColumn;
-                    _rColumns->push_back(xCol);
+                    _rColumns->push_back(pColumn);
                 }
                 else
                     bError = true;
@@ -1714,14 +1710,13 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co
         {
             OUString aNewColName(getUniqueColumnName(rColumnAlias));
 
-            OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
+            rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(),
                 ColumnValue::NULLABLE_UNKNOWN,0,0,DataType::VARCHAR,false,false,isCaseSensitive(),
                 OUString(),OUString(),OUString());
             pColumn->setFunction(true);
             pColumn->setAggregateFunction(bAggFkt);
 
-            Reference< XPropertySet> xCol = pColumn;
-            _rColumns->push_back(xCol);
+            _rColumns->push_back(pColumn);
         }
     }
 }
diff --git a/connectivity/source/sdbcx/VColumn.cxx b/connectivity/source/sdbcx/VColumn.cxx
index 23993453101a..07d40bd567c0 100644
--- a/connectivity/source/sdbcx/VColumn.cxx
+++ b/connectivity/source/sdbcx/VColumn.cxx
@@ -180,8 +180,7 @@ Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor(  )
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed);
 
-
-    OColumn* pNewColumn = new OColumn(  m_Name,
+    rtl::Reference<OColumn> pNewColumn = new OColumn(  m_Name,
                                         m_TypeName,
                                         m_DefaultValue,
                                         m_Description,
diff --git a/connectivity/source/sdbcx/VTable.cxx b/connectivity/source/sdbcx/VTable.cxx
index 528399a172d4..849ffc38b152 100644
--- a/connectivity/source/sdbcx/VTable.cxx
+++ b/connectivity/source/sdbcx/VTable.cxx
@@ -210,7 +210,7 @@ Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor(  )
     ::osl::MutexGuard aGuard(m_aMutex);
     checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
 
-    OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName);
+    rtl::Reference<OTable> pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName);
     pTable->setNew(true);
     return pTable;
 }
diff --git a/include/connectivity/PColumn.hxx b/include/connectivity/PColumn.hxx
index f2319ad2a56e..8cb089324a79 100644
--- a/include/connectivity/PColumn.hxx
+++ b/include/connectivity/PColumn.hxx
@@ -95,7 +95,7 @@ namespace connectivity::parse
             /** creates a single OParseColumn, as described by a result set meta data instance.
                 The column names are unique.
             */
-            static OParseColumn*
+            static rtl::Reference<OParseColumn>
                 createColumnForResultSet(
                     const css::uno::Reference< css::sdbc::XResultSetMetaData >& _rxResMetaData,
                     const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rxDBMetaData,


More information about the Libreoffice-commits mailing list