]> git.sesse.net Git - vlc/commitdiff
Fixed various memory leaks.
authorChristophe Massiot <massiot@videolan.org>
Thu, 21 Dec 2000 14:18:15 +0000 (14:18 +0000)
committerChristophe Massiot <massiot@videolan.org>
Thu, 21 Dec 2000 14:18:15 +0000 (14:18 +0000)
src/ac3_decoder/ac3_decoder_thread.c
src/audio_decoder/audio_decoder.c
src/input/input.c
src/input/input.h
src/input/input_programs.c
src/input/input_ps.c
src/spu_decoder/spu_decoder.c
src/video_parser/video_parser.c

index dee7050eb307bea528a9021508530c363d28699e..1af50205d1f64ecaf7b5f4154806ba25592d0854 100644 (file)
@@ -2,7 +2,7 @@
  * ac3_decoder_thread.c: ac3 decoder thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: ac3_decoder_thread.c,v 1.19 2000/12/21 13:25:50 massiot Exp $
+ * $Id: ac3_decoder_thread.c,v 1.20 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors:
  *
@@ -321,7 +321,8 @@ static void EndThread (ac3dec_thread_t * p_ac3dec)
     }
 
     /* Destroy descriptor */
-    free (p_ac3dec);
+    free( p_ac3dec->p_config );
+    free( p_ac3dec );
 
     intf_DbgMsg ("ac3dec debug: ac3 decoder thread %p destroyed\n", p_ac3dec);
 }
index 7bb0ef98d93549c05140743aeaaa03368f8e4733..96824928f3479bfb30e7ccfec357a80eb00d5d6e 100644 (file)
@@ -2,7 +2,7 @@
  * audio_decoder.c: MPEG audio decoder thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_decoder.c,v 1.40 2000/12/21 13:25:50 massiot Exp $
+ * $Id: audio_decoder.c,v 1.41 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -320,7 +320,8 @@ static void EndThread ( adec_thread_t *p_adec )
         vlc_mutex_unlock (&(p_adec->p_aout_fifo->data_lock));
     }
     /* Destroy descriptor */
-    free (p_adec);
+    free( p_adec->p_config );
+    free( p_adec );
 
     intf_DbgMsg ("adec debug: audio decoder thread %p destroyed\n", p_adec);
 }
index 7d83c1cb58f4796c4b33b1959dd957a9c71286f1..d93a13edab54c4c37cdccfe15ca0890ec926cf87 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.61 2000/12/21 13:54:15 massiot Exp $
+ * $Id: input.c,v 1.62 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors: 
  *
@@ -316,18 +316,38 @@ static void EndThread( input_thread_t * p_input )
     for( i_es_loop = 0; i_es_loop < p_input->i_selected_es_number;
          i_es_loop++ )
     {
-        p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->b_die = 1;
-        /* Make sure the thread leaves the GetByte() function */
-        vlc_mutex_lock( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_lock);
-        vlc_cond_signal( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_wait );
-        vlc_mutex_unlock( &p_input->pp_selected_es[i_es_loop]->p_decoder_fifo->data_lock );
+        decoder_fifo_t *    p_decoder_fifo;
+
+        p_decoder_fifo = p_input->pp_selected_es[i_es_loop]->p_decoder_fifo;
+        p_decoder_fifo->b_die = 1;
+
+        /* Make sure the thread leaves the NextDataPacket() function */
+        vlc_mutex_lock( &p_decoder_fifo->data_lock);
+        vlc_cond_signal( &p_decoder_fifo->data_wait );
+        vlc_mutex_unlock( &p_decoder_fifo->data_lock );
 
         /* Waiting for the thread to exit */
         vlc_thread_join( p_input->pp_selected_es[i_es_loop]->thread_id );
+
+        /* Freeing all packets still in the decoder fifo. */
+        while( !DECODER_FIFO_ISEMPTY( *p_decoder_fifo ) )
+        {
+            p_decoder_fifo->pf_delete_pes( p_decoder_fifo->p_packets_mgt,
+                                     DECODER_FIFO_START( *p_decoder_fifo ) );
+            DECODER_FIFO_INCSTART( *p_decoder_fifo );
+        }
         free( p_input->pp_selected_es[i_es_loop]->p_decoder_fifo );
     }
 
     /* Free demultiplexer's data */
+    p_input->p_plugin->pf_end( p_input );
+    free( p_input->p_plugin );
+
+    /* Free input structures */
+    input_EndStream( p_input );
+    free( p_input->pp_es );
+    free( p_input->pp_selected_es );
+    free( p_input );
 
     /* Update status */
     *pi_status = THREAD_OVER;
index 848f3f6c14a861e59aa8ee971bf0ee6212be3318..9a3a87d54eda2bafaf651db73e6ef97a6dd4f3a2 100644 (file)
@@ -2,7 +2,7 @@
  * input.h: structures of the input not exported to other modules
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input.h,v 1.4 2000/12/20 16:04:31 massiot Exp $
+ * $Id: input.h,v 1.5 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors:
  *
@@ -77,6 +77,7 @@ void NextDataPacket ( struct bit_stream_s * );
  * Prototypes from input_programs.c
  *****************************************************************************/
 void input_InitStream( struct input_thread_s *, size_t );
+void input_EndStream( struct input_thread_s * );
 struct pgrm_descriptor_s * input_AddProgram( struct input_thread_s *,
                                              u16, size_t );
 void input_DelProgram( struct input_thread_s *, u16 );
index 6e9e731a1804a2e0e9c56a97a08839f14b1f2139..d6e27b80c9b38e5e898244f18d09777cfc52eaaa 100644 (file)
@@ -3,7 +3,7 @@
  * FIXME : check the return value of realloc() and malloc() !
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_programs.c,v 1.11 2000/12/21 13:54:15 massiot Exp $
+ * $Id: input_programs.c,v 1.12 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors:
  *
@@ -65,6 +65,32 @@ void input_InitStream( input_thread_t * p_input, size_t i_data_len )
     }
 }
 
+/*****************************************************************************
+ * input_EndStream: free all stream descriptors
+ *****************************************************************************/
+void input_EndStream( input_thread_t * p_input )
+{
+    int i, j;
+
+    for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
+    {
+        for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
+        {
+            if( p_input->stream.pp_programs[i]->pp_es[j]->p_demux_data != NULL )
+            {
+                free( p_input->stream.pp_programs[i]->pp_es[j]->p_demux_data );
+            }
+            free( p_input->stream.pp_programs[i]->pp_es[j] );
+        }
+
+        if( p_input->stream.pp_programs[i]->p_demux_data != NULL )
+        {
+            free( p_input->stream.pp_programs[i]->p_demux_data );
+        }
+        free( p_input->stream.pp_programs[i] );
+    }
+}
+
 /*****************************************************************************
  * input_AddProgram: add and init a program descriptor
  *****************************************************************************
index 48cc24a33d068894ecc946abbc17a89370cc591f..e490f97f376ef25b2c3978418eeb4ba4e5264d50 100644 (file)
@@ -2,7 +2,7 @@
  * input_ps.c: PS demux and packet management
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input_ps.c,v 1.8 2000/12/20 18:45:43 massiot Exp $
+ * $Id: input_ps.c,v 1.9 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors: 
  *
@@ -417,6 +417,7 @@ input_capabilities_t * PSKludge( void )
 
     p_plugin = (input_capabilities_t *)malloc( sizeof(input_capabilities_t) );
     p_plugin->pf_init = PSInit;
+    p_plugin->pf_end = PSEnd;
     p_plugin->pf_read = PSRead;
     p_plugin->pf_demux = input_DemuxPS; /* FIXME: use i_p_config_t ! */
     p_plugin->pf_new_packet = NewPacket;
index c14a11c2d997cd3f9168445fccb60b73fdc64d5d..4458dc4808a38a6b9ed3acd1f02291409b2ef670 100644 (file)
@@ -20,9 +20,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-/* repompĂ© sur video_decoder.c
- * FIXME: passer en terminate/destroy avec les signaux supplĂ©mentaires ?? */
-
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -364,6 +361,7 @@ static void ErrorThread( spudec_thread_t *p_spudec )
 static void EndThread( spudec_thread_t *p_spudec )
 {
     intf_DbgMsg( "spudec debug: destroying spu decoder thread %p\n", p_spudec );
+    free( p_spudec->p_config );
     free( p_spudec );
     intf_DbgMsg( "spudec debug: spu decoder thread %p destroyed\n", p_spudec);
 }
index 4e9340412efdd1c20baf73da4bf5d52ecfaaee35..d733def903c05ac2c82c9ecc84040afc7644373d 100644 (file)
@@ -2,7 +2,7 @@
  * video_parser.c : video parser thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: video_parser.c,v 1.55 2000/12/21 13:25:51 massiot Exp $
+ * $Id: video_parser.c,v 1.56 2000/12/21 14:18:15 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -313,11 +313,6 @@ static void EndThread( vpar_thread_t *p_vpar )
 
     intf_DbgMsg("vpar debug: destroying video parser thread %p\n", p_vpar);
 
-#ifdef DEBUG
-    /* Check for remaining PES packets */
-    /* XXX?? */
-#endif
-
 #ifdef STATS
     intf_Msg("vpar stats: %d loops among %d sequence(s)\n",
              p_vpar->c_loops, p_vpar->c_sequences);
@@ -361,10 +356,6 @@ static void EndThread( vpar_thread_t *p_vpar )
              S.i_matrix_coefficients);
 #endif
 
-    /* Destroy thread structures allocated by InitThread */
-//    vout_DestroyStream( p_vpar->p_vout, p_vpar->i_stream );
-    /* XXX?? */
-
     /* Dispose of matrices if they have been allocated. */
     if( p_vpar->sequence.intra_quant.b_allocated )
     {
@@ -396,6 +387,7 @@ static void EndThread( vpar_thread_t *p_vpar )
     free( p_vpar->pp_vdec[0] );
 #endif
 
+    free( p_vpar->p_config );
     free( p_vpar );
 
     intf_DbgMsg("vpar debug: EndThread(%p)\n", p_vpar);