[vlc-devel] commit: Check malloc return value and fix a memory leak. ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu Aug 21 17:33:30 CEST 2008


vlc | branch: 0.8.6-bugfix | Rémi Denis-Courmont <rdenis at simphalempin.com> | Thu Aug 21 18:22:01 2008 +0300| [f51f8be0233e22114a0bb25ee1fcc9f4656ca5d7] | committer: Rémi Denis-Courmont 

Check malloc return value and fix a memory leak.

(cherry picked from commit def276b7faa4b528f6171b7375ab432ee59357a0)

Conflicts:

	modules/demux/tta.c

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

 modules/demux/tta.c |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/modules/demux/tta.c b/modules/demux/tta.c
index 47f83a4..a277fff 100644
--- a/modules/demux/tta.c
+++ b/modules/demux/tta.c
@@ -106,6 +106,9 @@ static int Open( vlc_object_t * p_this )
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
     
+    if( !p_sys )
+        return VLC_EGENERIC;
+
     /* Read the metadata */
     es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'T', 'T', 'A', '1' ) );
     fmt.audio.i_channels = GetWLE( &p_header[6] );
@@ -126,8 +129,20 @@ static int Open( vlc_object_t * p_this )
 
     i_seektable_size = sizeof(uint32_t)*p_sys->i_totalframes;
     p_seektable = (uint8_t *)malloc( i_seektable_size );
+    if( !p_seektable )
+    {
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
+
     stream_Read( p_demux->s, p_seektable, i_seektable_size );
-    p_sys->pi_seektable = (uint32_t *)malloc(i_seektable_size);
+    p_sys->pi_seektable = (uint32_t *)malloc( i_seektable_size );
+    if( !p_sys->pi_seektable )
+    {
+        free( p_seektable );
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
 
     for( i = 0; i < p_sys->i_totalframes; i++ )
         p_sys->pi_seektable[i] = GetDWLE( &p_seektable[i*4] );
@@ -137,8 +152,15 @@ static int Open( vlc_object_t * p_this )
     /* Store the header and Seektable for avcodec */
     fmt.i_extra = 22 + (p_sys->i_totalframes * 4) + 4;
     fmt.p_extra = malloc( fmt.i_extra );
-    memcpy( fmt.p_extra, p_header, 22 );
-    memcpy( fmt.p_extra+22, p_seektable, fmt.i_extra -22 );
+    if( !fmt.p_extra )
+    {
+        free( p_sys->pi_seektable );
+        free( p_seektable );
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
+    memcpy( (uint8_t*)fmt.p_extra, p_header, 22 );
+    memcpy( (uint8_t*)fmt.p_extra+22, p_seektable, fmt.i_extra -22 );
 
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
     free( p_seektable );
@@ -167,6 +189,7 @@ static void Close( vlc_object_t * p_this )
     demux_t        *p_demux = (demux_t*)p_this;
     demux_sys_t    *p_sys = p_demux->p_sys;
 
+    free( p_sys->pi_seektable );
     free( p_sys );
 }
 




More information about the vlc-devel mailing list