diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-06-11 15:31:17 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-06-11 17:36:55 +0200 |
commit | 5ea87cda46c1b4bd3f2f142d87e628f8cb4cdddb (patch) | |
tree | 4ce3de12ee3c41a220dd6189e2713daf28c2881a /dbaccess | |
parent | eaf30f98597f12c53d734935d62a84501cb201b4 (diff) |
Use comphelper::ScopeGuard to reliably uninitialize COM here
Change-Id: I60ccdf51731352b1749109a40c7ad61220a67d84
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96135
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/ui/dlg/adodatalinks.cxx | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/dbaccess/source/ui/dlg/adodatalinks.cxx b/dbaccess/source/ui/dlg/adodatalinks.cxx index 5792345ee61c..8ba7610fc854 100644 --- a/dbaccess/source/ui/dlg/adodatalinks.cxx +++ b/dbaccess/source/ui/dlg/adodatalinks.cxx @@ -24,6 +24,7 @@ #undef WB_RIGHT #include <msdasc.h> +#include <comphelper/scopeguard.hxx> #include <o3tl/char16_t2wchar_t.hxx> #include <initguid.h> @@ -43,11 +44,13 @@ OUString PromptNew(long hWnd) // Initialize COM hr = ::CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED ); - bool bDoUninit = true; if (FAILED(hr) && hr != RPC_E_CHANGED_MODE) std::abort(); - if (hr == RPC_E_CHANGED_MODE) - bDoUninit = false; + const bool bDoUninit = SUCCEEDED(hr); + comphelper::ScopeGuard g([bDoUninit] () { + if (bDoUninit) + CoUninitialize(); + }); // Instantiate DataLinks object. hr = CoCreateInstance( @@ -88,8 +91,6 @@ OUString PromptNew(long hWnd) piTmpConnection->Release( ); dlPrompt->Release( ); - if (bDoUninit) - CoUninitialize(); // Don't we need SysFreeString(_result)? return o3tl::toU(_result); } |