[vlc-devel] commit: Fix potential memleaks. ( Rémi Duraffort )

git version control git at videolan.org
Mon Aug 4 20:37:38 CEST 2008


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Mon Aug  4 20:39:08 2008 +0200| [e7832276fc7b3c70da6c5c79d167bb30fe597625] | committer: Rémi Duraffort 

Fix potential memleaks.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e7832276fc7b3c70da6c5c79d167bb30fe597625
---

 modules/visualization/visual/effects.c |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/modules/visualization/visual/effects.c b/modules/visualization/visual/effects.c
index df318cd..2b83cc8 100644
--- a/modules/visualization/visual/effects.c
+++ b/modules/visualization/visual/effects.c
@@ -391,10 +391,7 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
               p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
 
     if( !p_s16_buff )
-    {
-        msg_Err(p_aout,"out of memory");
         return -1;
-    }
 
     p_buffs = p_s16_buff;
     i_original     = config_GetInt ( p_aout, "spect-show-original" );
@@ -423,14 +420,14 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
 
     if( !p_effect->p_data )
     {
-        p_effect->p_data=(void *)malloc(i_nb_bands * sizeof(int) );
-        if( !p_effect->p_data)
+        p_effect->p_data=(void *)malloc( i_nb_bands * sizeof(int) );
+        if( !p_effect->p_data )
         {
-            msg_Err(p_aout,"out of memory");
+            free( p_s16_buff );
             return -1;
         }
         peaks = (int *)p_effect->p_data;
-        for( i = 0 ; i < i_nb_bands ; i++)
+        for( i = 0 ; i < i_nb_bands ; i++ )
         {
            peaks[i] = 0;
         }
@@ -443,7 +440,8 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     height = (int *)malloc( i_nb_bands * sizeof(int) );
     if( !height)
     {
-        msg_Err(p_aout,"out of memory");
+        free( p_effect->p_data );
+        free( p_s16_buff );
         return -1;
     }
 
@@ -463,6 +461,9 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     if( !p_state)
     {
         msg_Err(p_aout,"unable to initialize FFT transform");
+        free( height );
+        free( p_effect->p_data );
+        free( p_s16_buff );
         return -1;
     }
     p_buffs = p_s16_buff;
@@ -766,8 +767,6 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     fft_close( p_state );
 
     free( p_s16_buff );
-    p_s16_buff = NULL;
-
     free( height );
 
     return 0;




More information about the vlc-devel mailing list