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>
This commit is contained in:
Mike Kaganski 2020-06-11 15:31:17 +02:00
parent eaf30f9859
commit 5ea87cda46

View file

@ -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);
}