[vlc-commits] [Git][videolan/vlc][master] 4 commits: mmdevice: factorize the code to reset the device name
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sun Apr 12 17:07:44 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
263ff9a1 by Steve Lhomme at 2026-04-12T16:54:10+00:00
mmdevice: factorize the code to reset the device name
It's always set to NULL regardless of the if() branch.
- - - - -
a14bb764 by Steve Lhomme at 2026-04-12T16:54:10+00:00
mmdevice: use a local variable for the device name to use
On AUDCLNT_E_DEVICE_INVALIDATED we always reset the device_name to NULL (default device).
- - - - -
3c9bb048 by Steve Lhomme at 2026-04-12T16:54:10+00:00
mmdevice: fix device_name leaks when setting a new value
- - - - -
67362544 by Steve Lhomme at 2026-04-12T16:54:10+00:00
mmdevice: fix device name leak on error
- - - - -
1 changed file:
- modules/audio_output/mmdevice.c
Changes:
=====================================
modules/audio_output/mmdevice.c
=====================================
@@ -748,14 +748,18 @@ static int DeviceSelectLocked(audio_output_t *aout, const char *id)
assert(sys->device_status != DEVICE_PENDING);
sys->device_status = DEVICE_PENDING;
+ wchar_t *selected_device_name = NULL;
+ bool new_string = false;
if (id != NULL && strcmp(id, default_device_b) != 0)
{
- sys->device_name = ToWide(id); /* FIXME leak */
- if (unlikely(sys->device_name == NULL))
- return -1;
+ new_string = true;
+ selected_device_name = ToWide(id);
}
- else
- sys->device_name = NULL;
+ wchar_t *previous = sys->device_name;
+ sys->device_name = selected_device_name;
+ free(previous);
+ if (unlikely(selected_device_name == NULL && new_string))
+ return -1;
return DeviceRequestLocked(aout);
}
@@ -866,7 +870,9 @@ static void MMSessionMainloop(audio_output_t *aout, ISimpleAudioVolume *volume)
if (unlikely(hr == AUDCLNT_E_DEVICE_INVALIDATED ||
hr == AUDCLNT_E_RESOURCES_INVALIDATED))
{
+ wchar_t *previous = sys->device_name;
sys->device_name = NULL;
+ free(previous);
sys->device_status = DEVICE_PENDING;
/* The restart of the stream will be requested asynchronously */
}
@@ -901,18 +907,19 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
/* Yes, it's perfectly valid to request the same device, see Start()
* comments. */
- if (sys->device_name != NULL) /* Device selected explicitly */
+ wchar_t *current = sys->device_name;
+ if (current != NULL) /* Device selected explicitly */
{
- hr = IMMDeviceEnumerator_GetDevice(it, sys->device_name, &sys->dev);
+ hr = IMMDeviceEnumerator_GetDevice(it, current, &sys->dev);
if (FAILED(hr))
{
msg_Err(aout, "cannot get selected device %ls (error 0x%lX)",
- sys->device_name, hr);
+ current, hr);
hr = AUDCLNT_E_DEVICE_INVALIDATED;
}
else
{
- msg_Dbg(aout, "using selected device %ls", sys->device_name);
+ msg_Dbg(aout, "using selected device %ls", current);
sys->device_status = DEVICE_ACQUIRED;
}
}
@@ -923,18 +930,19 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
{ /* Default device selected by policy and with stream routing.
* "Do not use eMultimedia" says MSDN. */
msg_Dbg(aout, "using default device");
+ sys->device_name = NULL;
+ free(current);
+ current = NULL;
hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(it, eRender,
eConsole, &sys->dev);
if (FAILED(hr))
{
msg_Err(aout, "cannot get default device (error 0x%lX)", hr);
sys->device_status = DEVICE_ACQUISITION_FAILED;
- sys->device_name = NULL;
}
else
{
sys->device_status = DEVICE_ACQUIRED;
- sys->device_name = NULL;
}
}
@@ -948,7 +956,7 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
}
/* Report actual device */
- if (sys->device_name == NULL)
+ if (current == NULL)
aout_DeviceReport(aout, default_device_b);
else
{
@@ -1324,6 +1332,7 @@ static void Close(vlc_object_t *);
static int Open(vlc_object_t *obj)
{
audio_output_t *aout = (audio_output_t *)obj;
+ wchar_t *audio_device = NULL;
aout_sys_t *sys = malloc(sizeof (*sys));
if (unlikely(sys == NULL))
@@ -1343,7 +1352,6 @@ static int Open(vlc_object_t *obj)
sys->gain = 1.f;
sys->requested_volume = -1.f;
sys->requested_mute = -1;
- sys->device_name = NULL;
sys->default_device_changed = false;
if (!var_CreateGetBool(aout, "volume-save"))
@@ -1362,17 +1370,17 @@ static int Open(vlc_object_t *obj)
char *saved_device_b = var_InheritString(aout, "mmdevice-audio-device");
if (saved_device_b != NULL && strcmp(saved_device_b, default_device_b) != 0)
{
- sys->device_name = ToWide(saved_device_b); /* FIXME leak */
+ audio_device = ToWide(saved_device_b);
free(saved_device_b);
- if (unlikely(sys->device_name == NULL))
+ if (unlikely(audio_device == NULL))
goto error;
}
else
{
free(saved_device_b);
- sys->device_name = NULL;
}
+ sys->device_name = audio_device;
sys->device_status = DEVICE_PENDING;
if (vlc_clone(&sys->thread, MMThread, aout))
@@ -1398,6 +1406,7 @@ static int Open(vlc_object_t *obj)
return VLC_SUCCESS;
error:
+ free(audio_device);
if (sys->work_event != NULL)
CloseHandle(sys->work_event);
free(sys);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7531dd37c5ab3695f1b47092037a11964968ba51...67362544b766cd3043ae431d9547491a45116c5e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7531dd37c5ab3695f1b47092037a11964968ba51...67362544b766cd3043ae431d9547491a45116c5e
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list