Commit 33464f10 authored by Gildas Bazin's avatar Gildas Bazin

* src/input/*, modules/demux/util/sub.[ch]: cleanup and fixed memory leaks.
parent 361dab55
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sub.c * sub.c
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2003 VideoLAN * 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> * 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, ...@@ -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->p_es = NULL;
p_sub->i_subtitles = 0; p_sub->i_subtitles = 0;
p_sub->subtitle = NULL; p_sub->subtitle = NULL;
p_sub->p_vobsub_file = 0;
p_sub->p_input = p_input; p_sub->p_input = p_input;
if( !psz_name || !*psz_name ) if( !psz_name || !*psz_name )
...@@ -423,22 +424,11 @@ static int sub_open( subtitle_demux_t *p_sub, input_thread_t *p_input, ...@@ -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 ) if( p_sub->i_subtitles >= i_max )
{ {
i_max += 128; 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, msg_Err( p_sub, "out of memory");
sizeof( subtitle_t ) * i_max ) ) ) return VLC_ENOMEM;
{
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;
}
} }
} }
if( pf_read_subtitle( p_sub, &txt, if( pf_read_subtitle( p_sub, &txt,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sub.h * sub.h
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -159,6 +159,7 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub ) ...@@ -159,6 +159,7 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub )
msg_Info( p_sub, "subtitle stopped" ); msg_Info( p_sub, "subtitle stopped" );
if( p_sub ) if( p_sub )
{ {
p_sub->pf_close( p_sub );
vlc_object_detach( p_sub ); vlc_object_detach( p_sub );
if( p_sub->p_module ) if( p_sub->p_module )
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2004 VideoLAN * 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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -837,13 +837,14 @@ static int InitThread( input_thread_t * p_input ) ...@@ -837,13 +837,14 @@ static int InitThread( input_thread_t * p_input )
char **tmp2 = tmp; char **tmp2 = tmp;
for( i = 0; *tmp2 != NULL; i++ ) 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 ) ) ) i_microsecondperframe, i ) ) )
{ {
TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub ); 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 ); es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* subtitles.c * subtitles.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2003-2004 VideoLAN * 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> * Authors: Derk-Jan Hartman <hartman at videolan.org>
* This is adapted code from the GPL'ed MPlayer (http://mplayerhq.hu) * 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, ...@@ -243,7 +243,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
if( strcmp(sub_exts[i], tmp_fname_ext ) == 0 ) if( strcmp(sub_exts[i], tmp_fname_ext ) == 0 )
{ {
b_found = 1; 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; break;
} }
} }
...@@ -252,12 +253,13 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, ...@@ -252,12 +253,13 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
if( b_found ) if( b_found )
{ {
int i_prio = 0; 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 */ /* matches the movie name exactly */
i_prio = 4; 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 */ /* contains the movie name */
tmp += strlen( f_fname_trim ); tmp += strlen( f_fname_trim );
...@@ -281,17 +283,18 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, ...@@ -281,17 +283,18 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
if( i_prio >= fuzzy.i_int ) if( i_prio >= fuzzy.i_int )
{ {
sprintf( tmpresult, "%s%s", j == 0 ? f_dir : psz_path, de->d_name ); sprintf( tmpresult, "%s%s", j == 0 ? f_dir : psz_path,
msg_Dbg( p_this, "autodetected subtitle: %s with priority %d", de->d_name, i_prio ); de->d_name );
msg_Dbg( p_this, "autodetected subtitle: %s with "
"priority %d", de->d_name, i_prio );
if( ( f = fopen( tmpresult, "rt" ) ) ) if( ( f = fopen( tmpresult, "rt" ) ) )
{ {
fclose( f ); fclose( f );
result[i_sub_count].priority = i_prio; 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++; i_sub_count++;
} }
} }
} }
if( i_sub_count >= MAX_SUBTITLE_FILES ) break; if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
} }
...@@ -323,4 +326,3 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, ...@@ -323,4 +326,3 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
free( result ); free( result );
return result2; return result2;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment