[vlc-devel] commit: Check asprintf return value and fix a potential memleak. ( Rémi Duraffort )

git version control git at videolan.org
Tue Jul 15 19:57:14 CEST 2008


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Tue Jul 15 19:59:08 2008 +0200| [b2fcbc3a4a8f49b258b6f10cdf21da7723ac4981]

Check asprintf return value and fix a potential memleak.

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

 src/input/es_out.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index 24bd6ba..c7dac8e 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -177,12 +177,13 @@ static inline int EsOutGetClosedCaptionsChannel( vlc_fourcc_t fcc )
  *****************************************************************************/
 es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
 {
-    es_out_t     *out = malloc( sizeof( es_out_t ) );
-    es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
     vlc_value_t  val;
     int i;
 
+    es_out_t     *out = malloc( sizeof( es_out_t ) );
     if( !out ) return NULL;
+
+    es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) );
     if( !p_sys )
     {
         free( out );
@@ -476,17 +477,13 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id, es_format_t *fmt,
     {
         if( psz_language && *psz_language )
         {
-            char *temp;
-            text.psz_string = malloc( strlen( _("Track %i") )+
-                                      strlen( psz_language ) + 30 );
-            asprintf( &temp,  _("Track %i"), val.i_int );
-            sprintf( text.psz_string, "%s - [%s]", temp, psz_language );
-            free( temp );
+            if( asprintf( &text.psz_string, "%s %i - [%s]", _( "Track" ), val.i_int, psz_language ) == -1 )
+                text.psz_string = NULL;
         }
         else
         {
-            text.psz_string = malloc( strlen( _("Track %i") ) + 20 );
-            sprintf( text.psz_string, _("Track %i"), val.i_int );
+            if( asprintf( &text.psz_string, "%s %i", _( "Track" ), val.i_int ) == -1 )
+                text.psz_string = NULL;
         }
     }
 




More information about the vlc-devel mailing list