[vlc-commits] mkv: replace manual memory management of mkv_track_t::psz_codec

Filip Roséen git at videolan.org
Thu Sep 1 08:47:53 CEST 2016


vlc | branch: master | Filip Roséen <filip at atch.se> | Thu Sep  1 04:06:17 2016 +0200| [76233614e2f2516e047e44f7b7e5ac28a17221c0] | committer: Thomas Guillem

mkv: replace manual memory management of mkv_track_t::psz_codec

The previous implementation caused leakage of the data-member in
question due to missing clean-up. The manual memory management is now
replaced by std::string.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=76233614e2f2516e047e44f7b7e5ac28a17221c0
---

 modules/demux/mkv/matroska_segment.cpp       |  4 ++--
 modules/demux/mkv/matroska_segment_parse.cpp | 10 +++++-----
 modules/demux/mkv/mkv.hpp                    |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 49c240a..3e0bb4e 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -909,7 +909,7 @@ void matroska_segment_c::ComputeTrackPriority()
         tracks_map_t::key_type     track_id = it->first;
         tracks_map_t::mapped_type& track    = it->second;
 
-        if( unlikely( track.fmt.i_cat == UNKNOWN_ES || !track.psz_codec ) )
+        if( unlikely( track.fmt.i_cat == UNKNOWN_ES || track.codec.empty() ) )
         {
             msg_Warn( &sys.demuxer, "invalid track[%d]", static_cast<int>( track_id ) );
             track.p_es = NULL;
@@ -1076,7 +1076,7 @@ bool matroska_segment_c::ESCreate()
         tracks_map_t::key_type     track_id = it->first;
         tracks_map_t::mapped_type& track    = it->second;
 
-        if( unlikely( track.fmt.i_cat == UNKNOWN_ES || !track.psz_codec ) )
+        if( unlikely( track.fmt.i_cat == UNKNOWN_ES || track.codec.empty() ) )
         {
             msg_Warn( &sys.demuxer, "invalid track[%d]", static_cast<int>( track_id ) );
             track.p_es = NULL;
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 7a410b3..dcf201f 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -215,7 +215,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
     track.i_extra_data           = 0;
     track.p_extra_data           = NULL;
 
-    track.psz_codec              = NULL;
+    track.codec                  = "";
     track.b_dts_only             = false;
     track.b_pts_only             = false;
 
@@ -384,7 +384,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         }
         E_CASE( KaxCodecID, codecid )
         {
-            vars.tk->psz_codec = strdup( std::string( codecid ).c_str() );
+            vars.tk->codec = std::string( codecid );
             debug( vars, "Track CodecId=%s", std::string( codecid ).c_str() ) ;
         }
         E_CASE( KaxCodecPrivate, cpriv )
@@ -1245,7 +1245,7 @@ void matroska_segment_c::ParseCluster( KaxCluster *cluster, bool b_update_start_
 
 int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
 {
-    if( p_tk->psz_codec == NULL )
+    if( p_tk->codec.empty() )
     {
         msg_Err( &sys.demuxer, "Empty codec id" );
         p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
@@ -1819,14 +1819,14 @@ int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
     };
 
     try {
-        TrackCodecHandlers::Dispatcher().send( p_tk->psz_codec,
+        TrackCodecHandlers::Dispatcher().send( p_tk->codec.c_str(),
           TrackCodecHandlers::Payload( captures )
         );
     }
     catch (std::exception const& e)
     {
         msg_Err( &sys.demuxer, "Error when trying to initiate track (codec: %s): %s",
-          p_tk->psz_codec, e.what () );
+          p_tk->codec.c_str(), e.what () );
     }
 
     return 0;
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index 6bbca6b..6535814 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -193,7 +193,7 @@ class mkv_track_t
         unsigned int i_extra_data;
         uint8_t      *p_extra_data;
 
-        char         *psz_codec;
+        std::string  codec;
         bool         b_dts_only;
         bool         b_pts_only;
 



More information about the vlc-commits mailing list