[vlc-devel] [PATCH] hds: avoid crashing when no streams are present

Tristan Matthews le.businessman at gmail.com
Thu Jul 17 20:06:03 CEST 2014


Fixes some segfaults that occur when calling vlc http://flash.rit.edu/multirate.f4m.

---
 modules/stream_filter/hds/hds.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/modules/stream_filter/hds/hds.c b/modules/stream_filter/hds/hds.c
index 5119ba2..8c7d3a5 100644
--- a/modules/stream_filter/hds/hds.c
+++ b/modules/stream_filter/hds/hds.c
@@ -771,6 +771,9 @@ static void* download_thread( void* p )
     stream_t* s = (stream_t*) p_this;
     stream_sys_t* sys = s->p_sys;
 
+    if ( vlc_array_count( sys->hds_streams ) == 0 )
+        return NULL;
+
     // TODO: Change here for selectable stream
     hds_stream_t* hds_stream = sys->hds_streams->pp_elems[0];
 
@@ -1012,6 +1015,9 @@ static void* live_thread( void* p )
     stream_t* s = (stream_t*) p_this;
     stream_sys_t* sys = s->p_sys;
 
+    if ( vlc_array_count( sys->hds_streams ) == 0 )
+        return NULL;
+
     // TODO: Change here for selectable stream
     hds_stream_t* hds_stream = sys->hds_streams->pp_elems[0];
 
@@ -1436,15 +1442,21 @@ static void Close( vlc_object_t *p_this )
     stream_sys_t *p_sys = s->p_sys;
 
     // TODO: Change here for selectable stream
-    hds_stream_t *stream = s->p_sys->hds_streams->pp_elems[0];
+    hds_stream_t *stream = vlc_array_count(p_sys->hds_streams) ?
+        s->p_sys->hds_streams->pp_elems[0] : NULL;
 
     p_sys->closed = true;
-    vlc_cond_signal( & stream->dl_cond );
+    if (stream)
+        vlc_cond_signal( & stream->dl_cond );
 
     vlc_join( p_sys->dl_thread, NULL );
-    vlc_mutex_destroy( &stream->dl_lock );
-    vlc_cond_destroy( &stream->dl_cond );
-    vlc_mutex_destroy( &stream->abst_lock );
+
+    if (stream)
+    {
+        vlc_mutex_destroy( &stream->dl_lock );
+        vlc_cond_destroy( &stream->dl_cond );
+        vlc_mutex_destroy( &stream->abst_lock );
+    }
 
     if( p_sys->live )
     {
@@ -1595,6 +1607,9 @@ static int Read( stream_t *s, void *buffer, unsigned i_read )
 {
     stream_sys_t *p_sys = s->p_sys;
 
+    if ( vlc_array_count( p_sys->hds_streams ) == 0 )
+        return 0;
+
     // TODO: change here for selectable stream
     hds_stream_t *stream = s->p_sys->hds_streams->pp_elems[0];
     int length = 0;
@@ -1622,6 +1637,9 @@ static int Peek( stream_t *s, const uint8_t **pp_peek, unsigned i_peek )
 {
     stream_sys_t *p_sys = s->p_sys;
 
+    if ( vlc_array_count( p_sys->hds_streams ) == 0 )
+        return 0;
+
     // TODO: change here for selectable stream
     hds_stream_t *stream = p_sys->hds_streams->pp_elems[0];
 
-- 
1.9.3




More information about the vlc-devel mailing list