]> git.sesse.net Git - vlc/commitdiff
* src/input/*, modules/demux/util/sub.[ch]: cleanup and fixed memory leaks.
authorGildas Bazin <gbazin@videolan.org>
Mon, 26 Jan 2004 20:26:54 +0000 (20:26 +0000)
committerGildas Bazin <gbazin@videolan.org>
Mon, 26 Jan 2004 20:26:54 +0000 (20:26 +0000)
modules/demux/util/sub.c
modules/demux/util/sub.h
src/input/input.c
src/input/subtitles.c

index bf4958d6cfe094a654436f6894b28d1a54168151..e01b995c7a70a351e6e1cb9639d691f5bb2d5bc5 100644 (file)
@@ -2,7 +2,7 @@
  * sub.c
  *****************************************************************************
  * Copyright (C) 1999-2003 VideoLAN
- * $Id: sub.c,v 1.42 2004/01/26 20:02:15 gbazin Exp $
+ * $Id: sub.c,v 1.43 2004/01/26 20:26:54 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -270,6 +270,7 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
     p_sub->p_es = NULL;
     p_sub->i_subtitles = 0;
     p_sub->subtitle = NULL;
+    p_sub->p_vobsub_file = 0;
     p_sub->p_input = p_input;
 
     if( !psz_name || !*psz_name )
@@ -423,22 +424,11 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t  *p_input,
         if( p_sub->i_subtitles >= i_max )
         {
             i_max += 128;
-            if( p_sub->subtitle )
+            if( !( p_sub->subtitle = realloc( p_sub->subtitle,
+                                              sizeof(subtitle_t) * i_max ) ) )
             {
-                if( !( p_sub->subtitle = realloc( p_sub->subtitle,
-                                           sizeof( subtitle_t ) * i_max ) ) )
-                {
-                    msg_Err( p_sub, "out of memory");
-                    return VLC_ENOMEM;
-                }
-            }
-            else
-            {
-                if( !(  p_sub->subtitle = malloc( sizeof( subtitle_t ) * i_max ) ) )
-                {
-                    msg_Err( p_sub, "out of memory");
-                    return VLC_ENOMEM;
-                }
+                msg_Err( p_sub, "out of memory");
+                return VLC_ENOMEM;
             }
         }
         if( pf_read_subtitle( p_sub, &txt,
index fe9d4c15f7c7b71b31df2df0c5af3e97f63584d9..77fd3bc8bcccd9dec4992a7aac88a8d975555525 100644 (file)
@@ -2,7 +2,7 @@
  * sub.h
  *****************************************************************************
  * Copyright (C) 2001-2003 VideoLAN
- * $Id: sub.h,v 1.13 2004/01/26 20:02:15 gbazin Exp $
+ * $Id: sub.h,v 1.14 2004/01/26 20:26:54 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -159,6 +159,7 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub )
     msg_Info( p_sub, "subtitle stopped" );
     if( p_sub )
     {
+        p_sub->pf_close( p_sub );
         vlc_object_detach( p_sub );
         if( p_sub->p_module )
         {
index c9e91a5f58e03f0eab824c1258f4eda1e27b1bd5..e39ecfff1024cf7e9b0908ed078543a16048f90a 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2004 VideoLAN
- * $Id: input.c,v 1.278 2004/01/26 20:02:15 gbazin Exp $
+ * $Id: input.c,v 1.279 2004/01/26 20:26:54 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -837,13 +837,14 @@ static int InitThread( input_thread_t * p_input )
         char **tmp2 = tmp;
         for( i = 0; *tmp2 != NULL; i++ )
         {
-            if( ( p_sub = subtitle_New( p_input, *tmp2++,
+            if( ( p_sub = subtitle_New( p_input, *tmp2,
                                         i_microsecondperframe, i ) ) )
             {
                 TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );
             }
+            free( *tmp2++ );
         }
-        free(tmp);
+        free( tmp );
     }
 
     es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
index 5affe756b4822b6953b349962f0f2e7f11bd5c66..78b1d00aff78ea7394969ac58fd7bf085223b147 100644 (file)
@@ -2,7 +2,7 @@
  * subtitles.c
  *****************************************************************************
  * Copyright (C) 2003-2004 VideoLAN
- * $Id: subtitles.c,v 1.9 2004/01/26 19:20:10 gbazin Exp $
+ * $Id: subtitles.c,v 1.10 2004/01/26 20:26:54 gbazin Exp $
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
  * This is adapted code from the GPL'ed MPlayer (http://mplayerhq.hu)
@@ -243,7 +243,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                     if( strcmp(sub_exts[i], tmp_fname_ext ) == 0 )
                     {
                         b_found = 1;
-                        msg_Dbg( p_this, "found a possible subtitle: %s", de->d_name );
+                        msg_Dbg( p_this, "found a possible subtitle: %s",
+                                 de->d_name );
                         break;
                     }
                 }
@@ -252,12 +253,13 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                 if( b_found )
                 {
                     int i_prio = 0;
-                    if( !i_prio && strcmp( tmp_fname_trim, f_fname_trim ) == 0 )
+                    if( !i_prio && !strcmp( tmp_fname_trim, f_fname_trim ) )
                     {
                         /* matches the movie name exactly */
                         i_prio = 4;
                     }
-                    if( !i_prio && ( tmp = strstr( tmp_fname_trim, f_fname_trim ) ) )
+                    if( !i_prio &&
+                        ( tmp = strstr( tmp_fname_trim, f_fname_trim ) ) )
                     {
                         /* contains the movie name */
                         tmp += strlen( f_fname_trim );
@@ -281,17 +283,18 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
 
                     if( i_prio >= fuzzy.i_int )
                     {
-                        sprintf( tmpresult, "%s%s", j == 0 ? f_dir : psz_path, de->d_name );
-                        msg_Dbg( p_this, "autodetected subtitle: %s with priority %d", de->d_name, i_prio );
+                        sprintf( tmpresult, "%s%s", j == 0 ? f_dir : psz_path,
+                                 de->d_name );
+                        msg_Dbg( p_this, "autodetected subtitle: %s with "
+                                 "priority %d", de->d_name, i_prio );
                         if( ( f = fopen( tmpresult, "rt" ) ) )
                         {
                             fclose( f );
                             result[i_sub_count].priority = i_prio;
-                            result[i_sub_count].psz_fname = strdup( tmpresult );
+                            result[i_sub_count].psz_fname = strdup(tmpresult);
                             i_sub_count++;
                         }
                     }
-
                 }
                 if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
             }
@@ -323,4 +326,3 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     free( result );
     return result2;
 }
-