libvlcpp | branch: master | Hugo Beauzée-Luyssen <[email protected]> | Wed May 20 
13:51:22 2015 +0200| [1ca7de02c888eac1b5d19f46335fc8dcbb040fe0] | committer: 
Hugo Beauzée-Luyssen

MediaPlayer: getTracksDescription: Ensure the track list always gets released

An exception might be thrown by emplace_back

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

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

diff --git a/vlcpp/MediaPlayer.hpp b/vlcpp/MediaPlayer.hpp
index 2db4ab7..1d81d57 100644
--- a/vlcpp/MediaPlayer.hpp
+++ b/vlcpp/MediaPlayer.hpp
@@ -1634,16 +1634,17 @@ public:
 private:
     std::vector<TrackDescription> getTracksDescription( 
libvlc_track_description_t* tracks ) const
     {
+        if ( tracks == nullptr )
+            return {};
         std::vector<TrackDescription> result;
-        if ( tracks == NULL )
-            return result;
-        libvlc_track_description_t* p = tracks;
-        while ( p != NULL )
+        auto p = tracks;
+        std::unique_ptr<libvlc_track_description_t, 
decltype(&libvlc_track_description_list_release)>
+                devicePtr( tracks, libvlc_track_description_list_release );
+        while ( p != nullptr )
         {
             result.emplace_back( p );
             p = p->p_next;
         }
-        libvlc_track_description_list_release(tracks);
         return result;
     }
 

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to