[vlc-commits] VOBSUB: fixed memory leaks

Andrey Makhnutin git at videolan.org
Sun Jun 12 16:22:05 CEST 2011


vlc | branch: master | Andrey Makhnutin <the.boobl at gmail.com> | Sun Jun 12 18:08:38 2011 +0400| [a680337457e7fb3b8ca6e57ad5b3df41e7773e35] | committer: Jean-Baptiste Kempf

VOBSUB: fixed memory leaks

Signed-off-by: Andrey Makhnutin <the.boobl at gmail.com>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/vobsub.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/modules/demux/vobsub.c b/modules/demux/vobsub.c
index 38b2871..d39d685 100644
--- a/modules/demux/vobsub.c
+++ b/modules/demux/vobsub.c
@@ -156,10 +156,7 @@ static int Open ( vlc_object_t *p_this )
     p_sys->i_tracks = 0;
     p_sys->track = malloc( sizeof( vobsub_track_t ) );
     if( unlikely( !p_sys->track ) )
-    {
-        free( p_sys );
-        return VLC_ENOMEM;
-    }
+        goto error;
     p_sys->i_original_frame_width = -1;
     p_sys->i_original_frame_height = -1;
     p_sys->b_palette = false;
@@ -190,10 +187,8 @@ static int Open ( vlc_object_t *p_this )
 
     if( asprintf( &psz_vobname, "%s://%s", p_demux->psz_access,
                   p_demux->psz_location ) == -1 )
-    {
-        free( p_sys );
-        return VLC_EGENERIC;
-    }
+        goto error;
+
     i_len = strlen( psz_vobname );
     if( i_len >= 4 ) memcpy( psz_vobname + i_len - 4, ".sub", 4 );
 
@@ -204,12 +199,20 @@ static int Open ( vlc_object_t *p_this )
         msg_Err( p_demux, "couldn't open .sub Vobsub file: %s",
                  psz_vobname );
         free( psz_vobname );
-        free( p_sys );
-        return VLC_EGENERIC;
+        goto error;
     }
     free( psz_vobname );
 
     return VLC_SUCCESS;
+
+error:
+    /* Clean all subs from all tracks */
+    for( int i = 0; i < p_sys->i_tracks; i++ )
+        free( p_sys->track[i].p_subtitles );
+    free( p_sys->track );
+    free( p_sys );
+
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list