[vlc-commits] MediaPlayer: outputDeviceEnum: Ensure we always release the device list

Hugo Beauzée-Luyssen git at videolan.org
Mon May 25 10:04:45 CEST 2015


libvlcpp | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed May 20 11:02:41 2015 +0200| [48e272a7ccaff7f40115e07684bbedb17d95f013] | committer: Hugo Beauzée-Luyssen

MediaPlayer: outputDeviceEnum: Ensure we always release the device list

vector::emplace_back might throw and prevent
libvlc_audio_output_device_list_release from being called

> http://git.videolan.org/gitweb.cgi/libvlcpp.git/?a=commit;h=48e272a7ccaff7f40115e07684bbedb17d95f013
---

 vlcpp/MediaPlayer.hpp |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/vlcpp/MediaPlayer.hpp b/vlcpp/MediaPlayer.hpp
index ff7f119..2db4ab7 100644
--- a/vlcpp/MediaPlayer.hpp
+++ b/vlcpp/MediaPlayer.hpp
@@ -820,13 +820,14 @@ public:
      */
     std::vector<AudioOutputDeviceDescription> outputDeviceEnum()
     {
-        libvlc_audio_output_device_t* devices = libvlc_audio_output_device_enum(*this);
+        auto devices = libvlc_audio_output_device_enum(*this);
+        if ( devices == nullptr )
+            return {};
         std::vector<AudioOutputDeviceDescription> res;
-        if ( devices == NULL )
-            return res;
+        std::unique_ptr<libvlc_audio_output_device_t, decltype(&libvlc_audio_output_device_list_release)>
+                devicesPtr( devices, libvlc_audio_output_device_list_release);
         for ( auto* p = devices; p != NULL; p = p->p_next )
             res.emplace_back( p );
-        libvlc_audio_output_device_list_release( devices );
         return res;
     }
 



More information about the vlc-commits mailing list