[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: mmdevice: factorize the code to reset the device name

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Apr 16 10:59:39 UTC 2026



Felix Paul Kühne pushed to branch 3.0.x at VideoLAN / VLC


Commits:
d3e2b664 by Steve Lhomme at 2026-04-16T10:22:18+02:00
mmdevice: factorize the code to reset the device name

It's always set to NULL regardless of the if() branch.

(cherry picked from commit 263ff9a11fe890aaedc8a8c7c2516e7c04d70c1b)

- - - - -
526c9d2f by Steve Lhomme at 2026-04-16T10:22:18+02: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).

(cherry picked from commit a14bb76424bec5e496afe1de6cf9eb3f1c0d4399)

- - - - -
1edc14b1 by Steve Lhomme at 2026-04-16T10:22:18+02:00
mmdevice: fix device_name leaks when setting a new value

(cherry picked from commit 3c9bb0488b1ed0304c7bcde01980c6c66f2ab2d9) (edited)
edited:
- VLC 3 doesn't have the patch to implement non-blocking play

- - - - -
645d54dc by Steve Lhomme at 2026-04-16T10:22:18+02:00
mmdevice: fix device name leak on error

(cherry picked from commit 67362544b766cd3043ae431d9547491a45116c5e) (rebased)
rebased:
- VLC 3 uses critical sections

- - - - -


1 changed file:

- modules/audio_output/mmdevice.c


Changes:

=====================================
modules/audio_output/mmdevice.c
=====================================
@@ -767,14 +767,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);
 }
@@ -887,18 +891,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;
         }
     }
@@ -909,18 +914,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;
         }
     }
 
@@ -934,7 +940,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
     {
@@ -1306,6 +1312,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))
@@ -1325,7 +1332,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"))
@@ -1341,17 +1347,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, VLC_THREAD_PRIORITY_LOW))
@@ -1378,6 +1384,7 @@ static int Open(vlc_object_t *obj)
     return VLC_SUCCESS;
 
 error:
+    free(audio_device);
     DeleteCriticalSection(&sys->lock);
     free(sys);
     return VLC_EGENERIC;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cd4bc078dcd6438d991e5d7ace4070d03189a131...645d54dc217ea9abb577acbd3de053f75f00c7b7

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cd4bc078dcd6438d991e5d7ace4070d03189a131...645d54dc217ea9abb577acbd3de053f75f00c7b7
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list