[vlc-commits] lib: media: Fix memory leak on error case.

Hugo Beauzée-Luyssen git at videolan.org
Wed Jan 18 16:01:30 CET 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Jan 18 11:11:12 2017 +0100| [791c620e85cfca909d82fce09ffbc330d563bafe] | committer: Hugo Beauzée-Luyssen

lib: media: Fix memory leak on error case.

Always initialize ppp_slaves and always free it, to avoid leaking
pp_slaves when the first p_slave allocation fails
Fix CID #1372940

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

 lib/media.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/media.c b/lib/media.c
index fdd2445..f3be2c9 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -1194,6 +1194,7 @@ unsigned int libvlc_media_slaves_get( libvlc_media_t *p_md,
 {
     assert( p_md && ppp_slaves );
     input_item_t *p_input_item = p_md->p_input_item;
+    *ppp_slaves = NULL;
 
     vlc_mutex_lock( &p_input_item->lock );
 
@@ -1270,6 +1271,6 @@ void libvlc_media_slaves_release( libvlc_media_slave_t **pp_slaves,
         assert( pp_slaves );
         for( unsigned int i = 0; i < i_count; ++i )
             free( pp_slaves[i] );
-        free( pp_slaves );
     }
+    free( pp_slaves );
 }



More information about the vlc-commits mailing list