]> git.sesse.net Git - vlc/commitdiff
hds: avoid crashing when no streams are present
authorTristan Matthews <le.businessman@gmail.com>
Thu, 17 Jul 2014 18:03:19 +0000 (14:03 -0400)
committerTristan Matthews <le.businessman@gmail.com>
Thu, 17 Jul 2014 19:12:31 +0000 (15:12 -0400)
modules/stream_filter/hds/hds.c

index 5119ba2640b6eef28c500679d4ffe89e3c9cd36e..8c7d3a5b2d6941e022a5432a57c43662035b04da 100644 (file)
@@ -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];