Skip to content
Permalink
Browse files
8267819: CoInitialize/CoUninitialize should be called on same thread
Backport-of: 47700d8ef0175d4b457bb658371d2da4ec0a8181
  • Loading branch information
arapte committed Aug 19, 2021
1 parent 097780d commit 2eca45121632d0a5382bedb52a42468aa6811c00
@@ -51,6 +51,12 @@ void ReleaseNotificator(void *pObject) {
bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
m_pCallback = pCallback;
m_pData = pData;
bool bCallCoUninitialize = true;
bool bResult = false;

if (FAILED(CoInitialize(NULL))) {
bCallCoUninitialize = false;
}

HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
NULL,
@@ -59,11 +65,15 @@ bool GSTDirectSoundNotify::Init(GSTDSNotfierCallback pCallback, void *pData) {
if (SUCCEEDED(hr)) {
hr = m_pEnumerator->RegisterEndpointNotificationCallback(this);
if (SUCCEEDED(hr)) {
return true;
bResult = true;
}
}

return false;
if (bCallCoUninitialize) {
CoUninitialize();
}

return bResult;
}

void GSTDirectSoundNotify::Dispose() {
@@ -78,13 +88,6 @@ GSTDirectSoundNotify::GSTDirectSoundNotify() {
m_pEnumerator = NULL;
m_pCallback = NULL;
m_pData = NULL;
m_hrCoInit = CoInitialize(NULL);
}

GSTDirectSoundNotify::~GSTDirectSoundNotify() {
if (SUCCEEDED(m_hrCoInit)) {
CoUninitialize();
}
}

HRESULT GSTDirectSoundNotify::OnDefaultDeviceChanged(EDataFlow flow,
@@ -112,7 +115,7 @@ HRESULT GSTDirectSoundNotify::QueryInterface(REFIID iid, void** ppUnk) {

AddRef();

return S_OK;
return S_OK;
}

ULONG GSTDirectSoundNotify::AddRef() {
@@ -46,7 +46,6 @@ class GSTDirectSoundNotify : IMMNotificationClient
{
public:
GSTDirectSoundNotify();
~GSTDirectSoundNotify();

bool Init(GSTDSNotfierCallback pCallback, void *pData);
void Dispose();
@@ -67,7 +66,6 @@ class GSTDirectSoundNotify : IMMNotificationClient
IMMDeviceEnumerator* m_pEnumerator;
GSTDSNotfierCallback m_pCallback;
void *m_pData;
HRESULT m_hrCoInit;

// IUnknown
IFACEMETHODIMP QueryInterface(const IID& iid, void** ppUnk);

1 comment on commit 2eca451

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 2eca451 Aug 19, 2021

Please sign in to comment.