Skip to content

Commit

Permalink
Check for null pointer derefence
Browse files Browse the repository at this point in the history
The result of Activate should be checked. It may return NULL as described in https://learn.microsoft.com/en-us/windows/win32/api/mmdeviceapi/nf-mmdeviceapi-immdevice-activate
This will prevent a null pointer dereference when the Activate function fails.
Fixes #42 and see #42 for details.
  • Loading branch information
JJ-8 authored Nov 2, 2023
1 parent 71b3da1 commit 3c0d27d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cppsrc/win/win-sound-mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ bool Device::Update()
SafeRelease(&endpointVolume);
}

device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
HRESULT activateRes = device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL,
(LPVOID *)&endpointVolume);
if (activateRes != S_OK || endpointVolume == NULL)
{
return false;
}

if (device_cb == NULL)
device_cb = new SoundMixerAudioEndpointVolumeCallback(this);
Expand Down

0 comments on commit 3c0d27d

Please sign in to comment.