Commit 85a205b4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

adpcm: do not abuse fmt_in.p_extra, fix double free

parent a3d0339d
...@@ -72,6 +72,7 @@ struct decoder_sys_t ...@@ -72,6 +72,7 @@ struct decoder_sys_t
size_t i_samplesperblock; size_t i_samplesperblock;
date_t end_date; date_t end_date;
int16_t *prev;
}; };
static void DecodeAdpcmMs ( decoder_t *, int16_t *, uint8_t * ); static void DecodeAdpcmMs ( decoder_t *, int16_t *, uint8_t * );
...@@ -164,10 +165,12 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -164,10 +165,12 @@ static int OpenDecoder( vlc_object_t *p_this )
} }
/* Allocate the memory needed to store the decoder's structure */ /* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys = p_sys = malloc(sizeof(*p_sys));
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) if( unlikely(p_sys == NULL) )
return VLC_ENOMEM; return VLC_ENOMEM;
p_sys->prev = NULL;
switch( p_dec->fmt_in.i_codec ) switch( p_dec->fmt_in.i_codec )
{ {
case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */
...@@ -187,9 +190,9 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -187,9 +190,9 @@ static int OpenDecoder( vlc_object_t *p_this )
break; break;
case VLC_FOURCC('X','A','J', 0): /* EA ADPCM */ case VLC_FOURCC('X','A','J', 0): /* EA ADPCM */
p_sys->codec = ADPCM_EA; p_sys->codec = ADPCM_EA;
p_dec->fmt_in.p_extra = calloc( 2 * p_dec->fmt_in.audio.i_channels, p_sys->prev = calloc( 2 * p_dec->fmt_in.audio.i_channels,
sizeof( int16_t ) ); sizeof( int16_t ) );
if( p_dec->fmt_in.p_extra == NULL ) if( unlikely(p_sys->prev == NULL) )
{ {
free( p_sys ); free( p_sys );
return VLC_ENOMEM; return VLC_ENOMEM;
...@@ -245,6 +248,7 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -245,6 +248,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_dec->fmt_in.audio.i_bitspersample, p_sys->i_block, p_dec->fmt_in.audio.i_bitspersample, p_sys->i_block,
p_sys->i_samplesperblock ); p_sys->i_samplesperblock );
p_dec->p_sys = p_sys;
p_dec->fmt_out.i_cat = AUDIO_ES; p_dec->fmt_out.i_cat = AUDIO_ES;
p_dec->fmt_out.i_codec = VLC_CODEC_S16N; p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate; p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;
...@@ -349,8 +353,7 @@ static void CloseDecoder( vlc_object_t *p_this ) ...@@ -349,8 +353,7 @@ static void CloseDecoder( vlc_object_t *p_this )
decoder_t *p_dec = (decoder_t *)p_this; decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
if( p_sys->codec == ADPCM_EA ) free( p_sys->prev );
free( p_dec->fmt_in.p_extra );
free( p_sys ); free( p_sys );
} }
...@@ -741,7 +744,7 @@ static void DecodeAdpcmEA( decoder_t *p_dec, int16_t *p_sample, ...@@ -741,7 +744,7 @@ static void DecodeAdpcmEA( decoder_t *p_dec, int16_t *p_sample,
unsigned chans = p_dec->fmt_in.audio.i_channels; unsigned chans = p_dec->fmt_in.audio.i_channels;
const uint8_t *p_end = &p_buffer[p_sys->i_block]; const uint8_t *p_end = &p_buffer[p_sys->i_block];
int16_t *prev = (int16_t *)p_dec->fmt_in.p_extra; int16_t *prev = p_sys->prev;
int16_t *cur = prev + chans; int16_t *cur = prev + chans;
for (unsigned c = 0; c < chans; c++) for (unsigned c = 0; c < chans; c++)
......
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