[vlc-devel] [PATCH] demux/mkv: fix memory-leak on unknown elements

Filip Roséen filip at atch.se
Thu Jan 12 13:31:08 CET 2017


If the read element is not a KaxSegment we do not store it anywhere,
as such it will be leaked when we either read a new element, or assign
NULL to p_l0 to signal that we should abort parsing.

These additions make sure that we delete non-handled elements, effectively
preventing leaks of such elements.

---
 modules/demux/mkv/demux.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 481aa0dce2..56248e8f30 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -502,6 +502,8 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
 
     while (p_l0 != 0)
     {
+        bool b_l0_handled = false;
+
         if ( MKV_IS_ID( p_l0, KaxSegment) )
         {
             EbmlParser  *ep;
@@ -577,7 +579,12 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
                 p_segment1->segment = NULL;
                 delete p_segment1;
             }
+
+            b_l0_handled = true;
         }
+
+        EbmlElement* p_l0_prev = p_l0;
+
         if (p_l0->IsFiniteSize() )
         {
             p_l0->SkipData(*p_estream, KaxMatroska_Context);
@@ -587,6 +594,9 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
         {
             p_l0 = NULL;
         }
+
+        if( b_l0_handled == false )
+            delete p_l0_prev;
     }
 
     if ( !b_keep_stream )
-- 
2.11.0



More information about the vlc-devel mailing list