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

Julien Nabet (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 3 21:05:01 UTC 2020


 connectivity/source/drivers/ado/ADriver.cxx |   20 +++++++++++++++-----
 connectivity/source/inc/ado/ADriver.hxx     |    2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)

New commits:
commit 95e5d37b6e62eb39f2d5337e124e86b3d0c3f399
Author:     Julien Nabet <serval2412 at yahoo.fr>
AuthorDate: Fri May 29 23:58:59 2020 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 3 23:04:27 2020 +0200

    Improve COM library management in ADO
    
    Change-Id: I99a1c61068fec743847181b43f3d9278c85e95e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95174
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx
index 926a818eebb2..4ec59deeee36 100644
--- a/connectivity/source/drivers/ado/ADriver.cxx
+++ b/connectivity/source/drivers/ado/ADriver.cxx
@@ -45,20 +45,30 @@ using namespace com::sun::star::sdbcx;
 ODriver::ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB)
     : ODriver_BASE(m_aMutex)
     ,m_xORB(_xORB)
+    ,mnNbCallCoInitializeExForReinit(0)
 {
-     if ( FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)) )
+     HRESULT hr;
+     while ((hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)) == RPC_E_CHANGED_MODE)
      {
+         // so we're in RPC_E_CHANGED_MODE case
+         // the pb was it was already initialized with COINIT_MULTITHREADED
+         // close this init
          CoUninitialize();
-         int h = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
-         (void)h;
-         ++h;
+         // and increment counter for dtr part
+         ++mnNbCallCoInitializeExForReinit;
+
+         // and keep on the loop if there were multi initializations
      }
+     if (FAILED(hr))
+         std::abort();
 }
 
 ODriver::~ODriver()
 {
     CoUninitialize();
-    CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+    // Put back all the inits, if there were, before the use of ADO
+    for (int i = 0; i < mnNbCallCoInitializeExForReinit; ++i)
+        CoInitializeEx(nullptr, COINIT_MULTITHREADED);
 }
 
 void ODriver::disposing()
diff --git a/connectivity/source/inc/ado/ADriver.hxx b/connectivity/source/inc/ado/ADriver.hxx
index 22b23b4cada7..df017f2b6fa2 100644
--- a/connectivity/source/inc/ado/ADriver.hxx
+++ b/connectivity/source/inc/ado/ADriver.hxx
@@ -48,6 +48,8 @@ namespace connectivity
                                                         //  for this Driver
             css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB;
 
+            // to put back all the inits with COINIT_MULTITHREADED if needed
+            int mnNbCallCoInitializeExForReinit;
 
         public:
             ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB);


More information about the Libreoffice-commits mailing list