diff options
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); } |