[vlc-commits] sout_description: fix malloc usage

Rémi Denis-Courmont git at videolan.org
Mon Feb 16 18:47:54 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Feb 16 19:45:10 2015 +0200| [9b65068ef6cad297c0977b27a055a7ae09d2eb11] | committer: Rémi Denis-Courmont

sout_description: fix malloc usage

malloc(0) can return NULL. Don't use it to generate a non-NULL value
(NULL is the error code for sout_stream_t.pf_add).

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

 modules/stream_out/description.c |   19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/modules/stream_out/description.c b/modules/stream_out/description.c
index 71959c2..ac26422 100644
--- a/modules/stream_out/description.c
+++ b/modules/stream_out/description.c
@@ -63,10 +63,6 @@ struct sout_stream_sys_t
     mtime_t i_stream_start;
 };
 
-struct sout_stream_id_sys_t
-{
-};
-
 /*****************************************************************************
  * Open:
  *****************************************************************************/
@@ -111,12 +107,12 @@ static void Close( vlc_object_t *p_this )
 static sout_stream_id_sys_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
-    sout_stream_id_sys_t *id;
-    es_format_t *p_fmt_copy;
+    es_format_t *p_fmt_copy = malloc( sizeof( *p_fmt_copy ) );
+
+    if( unlikely(p_fmt_copy == NULL ) )
+        return NULL;
 
     msg_Dbg( p_stream, "Adding a stream" );
- 
-    p_fmt_copy = malloc(sizeof(es_format_t));
     es_format_Copy( p_fmt_copy, p_fmt );
 
     TAB_APPEND( p_sys->data->i_es, p_sys->data->es, p_fmt_copy );
@@ -124,15 +120,14 @@ static sout_stream_id_sys_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     if( p_sys->i_stream_start <= 0 )
         p_sys->i_stream_start = mdate();
 
-    id = malloc( sizeof( sout_stream_id_sys_t ) );
-    return id;
+    return (void *)p_fmt_copy;
 }
 
 static int Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     msg_Dbg( p_stream, "Removing a stream" );
-
-    free( id );
+    /* NOTE: id should be freed by the input manager, not here. */
+    (void) id;
     return VLC_SUCCESS;
 }
 



More information about the vlc-commits mailing list