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

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


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jul 24 10:02:06 2019 +0200| [ca086631dc1a39f1882976d9ec525176ada1aa9e] | 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>

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

 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 acddeb6e01..b2f6507668 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -261,28 +261,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, vlc_tick_t i_mk_date )



More information about the vlc-commits mailing list