]> git.sesse.net Git - vlc/commitdiff
* Fixed a segfault at EOF in input_es.c and input_ts.c (when i_read == 0).
authorSam Hocevar <sam@videolan.org>
Sun, 30 Dec 2001 04:26:53 +0000 (04:26 +0000)
committerSam Hocevar <sam@videolan.org>
Sun, 30 Dec 2001 04:26:53 +0000 (04:26 +0000)
  * Improved error recovery and avoided memleaks in the various input plugins.
  * Fixed a deadloop inserted by someone else into input_vcd.c :-)

plugins/dvd/input_dvd.c
plugins/dvdread/input_dvdread.c
plugins/mpeg_system/input_es.c
plugins/mpeg_system/input_ps.c
plugins/mpeg_system/input_ts.c
plugins/vcd/input_vcd.c

index a7fc2b20cdef17d9de04e711628084eec5e0954a..0876139a7b70495c2858b378ddd5bdf3e112c831 100644 (file)
@@ -9,7 +9,7 @@
  *  -dvd_udf to find files
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_dvd.c,v 1.114 2001/12/29 15:40:53 massiot Exp $
+ * $Id: input_dvd.c,v 1.115 2001/12/30 04:26:53 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -216,6 +216,7 @@ static void DVDInit( input_thread_t * p_input )
     if( dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS ) < 0 )
     {
         intf_ErrMsg( "dvd error: %s", dvdcss_error( p_dvd->dvdhandle ) );
+        input_BuffersEnd( p_input->p_method_data );
         p_input->b_error = 1;
         return;
     }
@@ -229,6 +230,7 @@ static void DVDInit( input_thread_t * p_input )
         intf_ErrMsg( "dvd error: allcation error in ifo" );
         dvdcss_close( p_dvd->dvdhandle );
         free( p_dvd );
+        input_BuffersEnd( p_input->p_method_data );
         p_input->b_error = 1;
         return;
     }
@@ -239,6 +241,7 @@ static void DVDInit( input_thread_t * p_input )
         IfoDestroy( p_dvd->p_ifo );
         dvdcss_close( p_dvd->dvdhandle );
         free( p_dvd );
+        input_BuffersEnd( p_input->p_method_data );
         p_input->b_error = 1;
         return;
     }
index 015d92e170cfaf1adc7b79717b79f2c22e13904e..19e5463ec4575ee116f4d27dbfc783c3b9d05527 100644 (file)
@@ -6,7 +6,7 @@
  * It depends on: libdvdread for ifo files and block reading.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_dvdread.c,v 1.10 2001/12/29 22:22:01 massiot Exp $
+ * $Id: input_dvdread.c,v 1.11 2001/12/30 04:26:53 sam Exp $
  *
  * Author: Stéphane Borel <stef@via.ecp.fr>
  *
@@ -203,6 +203,7 @@ static void DvdReadInit( input_thread_t * p_input )
 
     if( (p_input->p_method_data = input_BuffersInit()) == NULL )
     {
+        free( p_dvd );
         p_input->b_error = 1;
         return;
     }
@@ -216,6 +217,7 @@ static void DvdReadInit( input_thread_t * p_input )
     {
         intf_ErrMsg( "dvdread error: can't open VMG info" );
         DVDClose( p_dvd->p_dvdread );
+        input_BuffersEnd( p_input->p_method_data );
         free( p_dvd );
         p_input->b_error = 1;
         return;
index afa78ed3ea9600a6004d22cc65b894e38a61f749..700a61e82e1996bc2a41bd2f44b748b24cd795cf 100644 (file)
@@ -2,7 +2,7 @@
  * input_es.c: Elementary Stream demux and packet management
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: input_es.c,v 1.9 2001/12/29 03:07:51 massiot Exp $
+ * $Id: input_es.c,v 1.10 2001/12/30 04:26:53 sam Exp $
  *
  * Author: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -222,15 +222,13 @@ static int ESRead( input_thread_t * p_input,
          * back to the buffer allocator. */
         int i_loop;
 
-        for( i_loop = 0; i_loop + 1 < i_read; i_loop++ )
+        for( i_loop = 0; i_loop < i_read; i_loop++ )
         {
-            p_data = p_data->p_next;
-        }
-        p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next );
-        if( i_read != 0 )
-        {
-            p_data->p_next = NULL;
+            pp_data = &(*pp_data)->p_next;
         }
+
+        p_input->pf_delete_packet( p_input->p_method_data, *pp_data );
+        *pp_data = NULL;
     }
 
     return( i_read );
index 9090c7592ca5ba48f0afc8a35dc526a81ced6c4a..ef714e2df28de1577d8fd06a08be9bdb6c08c251 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ps.c,v 1.9 2001/12/29 03:07:51 massiot Exp $
+ * $Id: input_ps.c,v 1.10 2001/12/30 04:26:53 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
@@ -181,6 +181,7 @@ static void PSInit( input_thread_t * p_input )
         if( p_input->p_stream == NULL )
         {
             intf_ErrMsg( "Cannot open file (%s)", strerror(errno) );
+            input_BuffersEnd( p_input->p_method_data );
             p_input->b_error = 1;
             return;
         }
index e18cd44cb3744db5d73b118a3d51edd169c60af7..fe1254ebda4d4ad7ace0548afe80736284bb271c 100644 (file)
@@ -2,7 +2,7 @@
  * input_ts.c: TS demux and netlist management
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: input_ts.c,v 1.8 2001/12/29 03:07:51 massiot Exp $
+ * $Id: input_ts.c,v 1.9 2001/12/30 04:26:53 sam Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org>
  *
@@ -325,33 +325,22 @@ static int TSRead( input_thread_t * p_input,
         i_read /= TS_PACKET_SIZE;
 
         /* Check correct TS header */
-        for( i_loop = 0; i_loop + 1 < i_read; i_loop++ )
+        for( i_loop = 0; i_loop < i_read; i_loop++ )
         {
-            if( p_data->p_demux_start[0] != 0x47 )
+            if( (*pp_data)->p_demux_start[0] != 0x47 )
             {
                 intf_ErrMsg( "input error: bad TS packet (starts with "
                              "0x%.2x, should be 0x47)",
                              p_data->p_demux_start[0] );
             }
-            p_data = p_data->p_next;
-        }
-
-        /* Last packet */
-        if( p_data->p_demux_start[0] != 0x47 )
-        {
-            intf_ErrMsg( "input error: bad TS packet (starts with "
-                         "0x%.2x, should be 0x47)",
-                         p_data->p_demux_start[0] );
+            pp_data = &(*pp_data)->p_next;
         }
 
         if( i_read != TS_READ_ONCE )
         {
             /* Delete remaining packets */
-            p_input->pf_delete_packet( p_input->p_method_data, p_data->p_next );
-            if( i_read != 0 )
-            {
-                p_data->p_next = NULL;
-            }
+            p_input->pf_delete_packet( p_input->p_method_data, *pp_data );
+            *pp_data = NULL;
         }
     }
     return( i_read );
index 333e9a4aaf871bc71d04996bbff54cde6ed224c6..b1e691b82a6cb9b47dee78e9e539f0d7517cb250 100644 (file)
@@ -241,6 +241,9 @@ static void VCDInit( input_thread_t * p_input )
     if ( VCDReadToc( p_vcd ) == -1 )
     {
         intf_ErrMsg( "vcd error: could not read TOC" );
+        input_BuffersEnd( p_input->p_method_data );
+        p_input->b_error = 1;
+        return;
     }
 
     /* Set stream and area data */
@@ -413,8 +416,7 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data )
     i_packet = 0;
     *pp_data = NULL;
 
-    while( i_packet < VCD_DATA_ONCE
-            && !p_vcd->b_end_of_track )
+    while( i_packet < VCD_DATA_ONCE && !p_vcd->b_end_of_track )
     {
         if ( VCDReadSector( p_vcd, p_buffer ) == -1 )
         {
@@ -436,7 +438,8 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data )
                 /* It is common for MPEG-1 streams to pad with zeros
                  * (although it is forbidden by the recommendation), so
                  * don't bother everybody in this case. */
-                intf_WarnMsg( 3, "vcd warning: garbage at input" );
+                intf_WarnMsg( 12, "vcd warning: garbage at input" );
+                break;
             }
 
             while( (i_header & 0xFFFFFF00) != 0x100L
@@ -524,6 +527,8 @@ static int VCDRead( input_thread_t * p_input, data_packet_t ** pp_data )
             /* Give the packet to the other input stages. */
             *pp_data = p_data;
             pp_data = &p_data->p_next;
+
+            i_packet++;
         }
     }