[vlc-commits] demux: mkv: fix vector erase in destructor

Alexandre Janniaux git at videolan.org
Wed Aug 14 18:24:18 CEST 2019


vlc/vlc-3.0 | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jul 24 10:02:06 2019 +0200| [493ab98a131e87c006284987fd6674942faf7721] | committer: Hugo Beauzée-Luyssen

demux: mkv: fix vector erase in destructor

Ref #22474

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
(cherry picked from commit ca086631dc1a39f1882976d9ec525176ada1aa9e)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 modules/demux/mkv/demux.cpp | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 804d979b1b..7823ca1940 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -701,28 +701,20 @@ bool demux_sys_t::PreloadLinked()
 
 void demux_sys_t::FreeUnused()
 {
-    for (std::vector<matroska_stream_c*>::reverse_iterator i = streams.rbegin();
-         i != streams.rend(); ++i)
-    {
-        matroska_stream_c *p_s = *i;
-        if( !p_s->isUsed() )
-        {
-            std::advance(i, 1);
-            streams.erase( i.base() );
-            delete p_s;
-        }
-    }
-    for (std::vector<matroska_segment_c*>::reverse_iterator i = opened_segments.rbegin();
-         i != opened_segments.rend(); ++i)
-    {
-        matroska_segment_c *p_sg = *i;
-        if( !p_sg->b_preloaded )
-        {
-            std::advance(i, 1);
-            opened_segments.erase( i.base() );
-            delete p_sg;
-        }
-    }
+    auto sIt = std::remove_if(begin(streams), end(streams), [](const matroska_stream_c* p_s) {
+        return !p_s->isUsed();
+    });
+    for (auto it = sIt; it != end(streams); ++it)
+        delete *it;
+    streams.erase(sIt, end(streams));
+
+    auto sgIt = std::remove_if(begin(opened_segments), end(opened_segments),
+                [](const matroska_segment_c* p_sg) {
+        return !p_sg->b_preloaded;
+    });
+    for (auto it = sgIt; it != end(opened_segments); ++it)
+        delete *it;
+    opened_segments.erase(sgIt, end(opened_segments));
 }
 
 bool demux_sys_t::PreparePlayback( virtual_segment_c & new_vsegment, mtime_t i_mk_date )



More information about the vlc-commits mailing list