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