[vlc-devel] [RFC 16/38] demux/vobsub: replaced usage of x{realloc, malloc}
Filip Roséen
filip at videolabs.io
Mon Jun 27 13:43:27 CEST 2016
As well as fixing places where xrealloc/xmalloc were used, this patch
properly propogates any error from within ParseVobSubIDX up to Open
(which has code responsible for clean-up of the relevant pieces).
---
modules/demux/vobsub.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/modules/demux/vobsub.c b/modules/demux/vobsub.c
index fab7f8e..a8c4600 100644
--- a/modules/demux/vobsub.c
+++ b/modules/demux/vobsub.c
@@ -161,7 +161,8 @@ static int Open ( vlc_object_t *p_this )
TextLoad( &p_sys->txt, p_demux->s );
/* Parse it */
- ParseVobSubIDX( p_demux );
+ if( ParseVobSubIDX( p_demux ) )
+ goto error;
/* Unload */
TextUnload( &p_sys->txt );
@@ -526,6 +527,7 @@ static int ParseVobSubIDX( demux_t *p_demux )
Spec (or lack of) doesn't define any limit */
int i_track_id;
es_format_t fmt;
+ vobsub_track_t * p_track_orig;
/* Lets start a new track */
if( sscanf( line, "id: %32[^ ,], index: %d",
@@ -539,19 +541,31 @@ static int ParseVobSubIDX( demux_t *p_demux )
language[0] = '\0';
}
+ p_track_orig = p_sys->track;
+
p_sys->i_tracks++;
- p_sys->track = xrealloc( p_sys->track,
+ p_sys->track = realloc( p_sys->track,
sizeof( vobsub_track_t ) * (p_sys->i_tracks + 1 ) );
+ if( unlikely( !p_sys->track ) )
+ {
+ p_sys->i_tracks--;
+ p_sys->track = p_track_orig;
+ return VLC_ENOMEM;
+ }
+
/* Init the track */
current_tk = &p_sys->track[p_sys->i_tracks - 1];
memset( current_tk, 0, sizeof( vobsub_track_t ) );
current_tk->i_current_subtitle = 0;
current_tk->i_subtitles = 0;
- current_tk->p_subtitles = xmalloc( sizeof( subtitle_t ) );
+ current_tk->p_subtitles = malloc( sizeof( subtitle_t ) );
current_tk->i_track_id = i_track_id;
current_tk->i_delay = (int64_t)0;
+ if( unlikely( !current_tk->p_subtitles ) )
+ return VLC_ENOMEM;
+
es_format_Init( &fmt, SPU_ES, VLC_CODEC_SPU );
fmt.subs.spu.i_original_frame_width = p_sys->i_original_frame_width;
fmt.subs.spu.i_original_frame_height = p_sys->i_original_frame_height;
@@ -581,6 +595,7 @@ static int ParseVobSubIDX( demux_t *p_demux )
{
vobsub_track_t *current_tk = &p_sys->track[p_sys->i_tracks - 1];
subtitle_t *current_sub;
+ subtitle_t *p_subtitles_orig;
if( line[count-3] == '-' )
{
@@ -593,10 +608,20 @@ static int ParseVobSubIDX( demux_t *p_demux )
ms ) * 1000;
i_location = loc;
+ p_subtitles_orig = current_tk->p_subtitles;
+
current_tk->i_subtitles++;
current_tk->p_subtitles =
- xrealloc( current_tk->p_subtitles,
+ realloc( current_tk->p_subtitles,
sizeof( subtitle_t ) * (current_tk->i_subtitles + 1 ) );
+
+ if( unlikely( !current_tk->p_subtitles ) )
+ {
+ current_tk->i_subtitles--;
+ current_tk->p_subtitles = p_subtitles_orig;
+ return VLC_ENOMEM;
+ }
+
current_sub = ¤t_tk->p_subtitles[current_tk->i_subtitles - 1];
current_sub->i_start = i_start * i_sign;
--
2.9.0
More information about the vlc-devel
mailing list