[vlc-commits] mkv: use a destructor to release all the resources allocated in an mkv_track_t

Steve Lhomme git at videolan.org
Mon Jul 31 15:23:30 CEST 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Mon Jul 31 15:02:58 2017 +0200| [ff3bebc15a72ca3317913f1e803103e4d5b52bff] | committer: Jean-Baptiste Kempf

mkv: use a destructor to release all the resources allocated in an mkv_track_t

This way we can't forget any when releasing it from various places.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mkv/matroska_segment.cpp       | 10 ----------
 modules/demux/mkv/matroska_segment_parse.cpp |  8 --------
 modules/demux/mkv/mkv.cpp                    | 11 +++++++++++
 modules/demux/mkv/mkv.hpp                    |  1 +
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index f4061d60ba..982792d347 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -65,16 +65,6 @@ matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estr
 
 matroska_segment_c::~matroska_segment_c()
 {
-    for( tracks_map_t::iterator it = tracks.begin(); it != tracks.end(); ++it)
-    {
-        mkv_track_t & track = *it->second;
-
-        es_format_Clean( &track.fmt );
-        delete track.p_compression_data;
-        delete track.p_sys;
-        free( track.p_extra_data );
-    }
-
     free( psz_writing_application );
     free( psz_muxing_application );
     free( psz_segment_filename );
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index c581fd99c2..dd48d078f7 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -673,8 +673,6 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
     if( p_track->i_number == 0 )
     {
         msg_Warn( &sys.demuxer, "Missing KaxTrackNumber, discarding track!" );
-        es_format_Clean( &p_track->fmt );
-        free(p_track->p_extra_data);
         delete p_track;
         return;
     }
@@ -688,8 +686,6 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
             zlib_decompress_extra( &sys.demuxer, *p_track ) )
         {
             msg_Err(&sys.demuxer, "Couldn't handle the track %u compression", p_track->i_number );
-            es_format_Clean( &p_track->fmt );
-            free(p_track->p_extra_data);
             delete p_track;
             return;
         }
@@ -697,8 +693,6 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
         if( !TrackInit( p_track ) )
         {
             msg_Err(&sys.demuxer, "Couldn't init track %u", p_track->i_number );
-            es_format_Clean( &p_track->fmt );
-            free(p_track->p_extra_data);
             delete p_track;
             return;
         }
@@ -708,8 +702,6 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
     else
     {
         msg_Err( &sys.demuxer, "Track Entry %u not supported", p_track->i_number );
-        es_format_Clean( &p_track->fmt );
-        free(p_track->p_extra_data);
         delete p_track;
     }
 }
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index bee64053e9..23e7adbc72 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -849,3 +849,14 @@ mkv_track_t::mkv_track_t(enum es_format_category_e es_cat) :
             break;
     }
 }
+
+mkv_track_t::~mkv_track_t()
+{
+    es_format_Clean( &fmt );
+    assert(p_es == NULL); // did we leak an ES ?
+
+    free(p_extra_data);
+
+    delete p_compression_data;
+    delete p_sys;
+}
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index 4022cf09fc..b3b175d9b4 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -184,6 +184,7 @@ class mkv_track_t
 {
     public:
         mkv_track_t(enum es_format_category_e es_cat);
+        ~mkv_track_t();
 
         typedef unsigned int track_id_t;
 



More information about the vlc-commits mailing list