]> git.sesse.net Git - vlc/blobdiff - src/input/demux.c
Avoid potential segfault and fix potential memleak.
[vlc] / src / input / demux.c
index 26bdc36845f31c73240193945c16532392da3668..9aa2105cf7835307ce2d8edec31b61206cb8a342 100644 (file)
@@ -54,7 +54,7 @@ demux_t *__demux_New( vlc_object_t *p_obj,
     p_demux->psz_path   = strdup( psz_path );
 
     /* Take into account "demux" to be able to do :demux=dump */
-    if( *p_demux->psz_demux == '\0' )
+    if( p_demux->psz_demux && *p_demux->psz_demux == '\0' )
     {
         free( p_demux->psz_demux );
         p_demux->psz_demux = var_GetNonEmptyString( p_obj, "demux" );
@@ -322,6 +322,8 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux,
     if( psz_demux == NULL || *psz_demux == '\0' ) return NULL;
 
     s = vlc_stream_create( p_obj );
+    if( s == NULL )
+        return NULL;
     s->pf_read   = DStreamRead;
     s->pf_peek   = DStreamPeek;
     s->pf_control= DStreamControl;
@@ -330,6 +332,11 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux,
     s->b_little_endian = false;
 
     s->p_sys = malloc( sizeof( d_stream_sys_t) );
+    if( s->p_sys == NULL )
+    {
+        vlc_object_release( s );
+        return NULL;
+    }
     p_sys = (d_stream_sys_t*)s->p_sys;
 
     p_sys->i_pos = 0;
@@ -341,8 +348,8 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux,
     /* decoder fifo */
     if( ( p_sys->p_fifo = block_FifoNew() ) == NULL )
     {
-        msg_Err( s, "out of memory" );
         vlc_object_release( s );
+        free( p_sys->psz_name );
         free( p_sys );
         return NULL;
     }
@@ -351,6 +358,7 @@ stream_t *__stream_DemuxNew( vlc_object_t *p_obj, const char *psz_demux,
                            VLC_THREAD_PRIORITY_INPUT, false ) )
     {
         vlc_object_release( s );
+        free( p_sys->psz_name );
         free( p_sys );
         return NULL;
     }