[vlc-devel] [PATCH 2/2] sout: description: make the ownership of es_format clear

Zhao Zhili quinkblack at foxmail.com
Sun Sep 30 07:01:28 CEST 2018


---
 modules/stream_out/description.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/modules/stream_out/description.c b/modules/stream_out/description.c
index f22387b..63124e2 100644
--- a/modules/stream_out/description.c
+++ b/modules/stream_out/description.c
@@ -113,21 +113,39 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
         return NULL;
 
     msg_Dbg( p_stream, "Adding a stream" );
-    es_format_Copy( p_fmt_copy, p_fmt );
+    if( es_format_Copy( p_fmt_copy, p_fmt ) != VLC_SUCCESS )
+    {
+        free( p_fmt_copy );
+        return NULL;
+    }
 
-    TAB_APPEND( p_sys->data->i_es, p_sys->data->es, p_fmt_copy );
+    es_format_t *p_fmt_copy2 = malloc( sizeof( *p_fmt_copy2 ) );
+    if( unlikely(p_fmt_copy2 == NULL ) )
+        goto error;
+
+    if( es_format_Copy( p_fmt_copy2, p_fmt ) != VLC_SUCCESS )
+    {
+        free( p_fmt_copy2 );
+        goto error;
+    }
+    TAB_APPEND( p_sys->data->i_es, p_sys->data->es, p_fmt_copy2 );
 
     if( p_sys->i_stream_start == VLC_TICK_INVALID )
         p_sys->i_stream_start = vlc_tick_now();
 
     return (void *)p_fmt_copy;
+
+error:
+    es_format_Clean( p_fmt_copy );
+    free( p_fmt_copy );
+    return NULL;
 }
 
 static void Del( sout_stream_t *p_stream, void *id )
 {
     msg_Dbg( p_stream, "Removing a stream" );
-    /* NOTE: id should be freed by the input manager, not here. */
-    (void) id;
+    es_format_Clean( (es_format_t *)id);
+    free( id );
 }
 
 static int Send( sout_stream_t *p_stream, void *id, block_t *p_buffer )
-- 
2.9.5





More information about the vlc-devel mailing list