From 5ea87cda46c1b4bd3f2f142d87e628f8cb4cdddb Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 11 Jun 2020 15:31:17 +0200 Subject: [PATCH] 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 --- dbaccess/source/ui/dlg/adodatalinks.cxx | 11 ++++++----- 1 file 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 +#include #include #include @@ -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); }