From e03af4423dcaef209627ca028c66973b5cc3c647 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell <greg@xiph.org> Date: Sun, 4 Sep 2011 04:43:11 -0400 Subject: [PATCH] Prevent double free on encoder/decoder init failure. --- src/opus_decoder.c | 18 ++++++------------ src/opus_encoder.c | 11 +++-------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 4361e5b11..2a4823bf2 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -88,10 +88,9 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) return OPUS_BAD_ARG; OPUS_CLEAR((char*)st, opus_decoder_get_size(channels)); /* Initialize SILK encoder */ - ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); - if( ret ) { - return OPUS_INTERNAL_ERROR; - } + ret = silk_Get_Decoder_Size(&silkDecSizeBytes); + if(ret)return OPUS_INTERNAL_ERROR; + silkDecSizeBytes = align(silkDecSizeBytes); st->silk_dec_offset = align(sizeof(OpusDecoder)); st->celt_dec_offset = st->silk_dec_offset+silkDecSizeBytes; @@ -103,22 +102,17 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) /* Reset decoder */ ret = silk_InitDecoder( silk_dec ); - if( ret ) { - goto failure; - } + if(ret)return OPUS_INTERNAL_ERROR; /* Initialize CELT decoder */ ret = celt_decoder_init(celt_dec, Fs, channels); - if (ret != OPUS_OK) - goto failure; + if(ret!=OPUS_OK)return OPUS_INTERNAL_ERROR; + celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0)); st->prev_mode = 0; st->frame_size = Fs/400; return OPUS_OK; -failure: - opus_free(st); - return OPUS_INTERNAL_ERROR; } OpusDecoder *opus_decoder_create(opus_int32 Fs, int channels, int *error) diff --git a/src/opus_encoder.c b/src/opus_encoder.c index a88f7fd65..3e07c79b7 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -162,8 +162,7 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat st->Fs = Fs; ret = silk_InitEncoder( silk_enc, &st->silk_mode ); - if (ret) - goto failure; + if(ret)return OPUS_INTERNAL_ERROR; /* default SILK parameters */ st->silk_mode.nChannelsAPI = channels; @@ -183,8 +182,8 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat /* Create CELT encoder */ /* Initialize CELT encoder */ err = celt_encoder_init(celt_enc, Fs, channels); - if (err != OPUS_OK) - goto failure; + if(err!=OPUS_OK)return OPUS_INTERNAL_ERROR; + celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0)); st->use_vbr = 0; @@ -213,10 +212,6 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat st->bandwidth = OPUS_BANDWIDTH_FULLBAND; return OPUS_OK; - -failure: - opus_free(st); - return OPUS_INTERNAL_ERROR; } static unsigned char gen_toc(int mode, int framerate, int bandwidth, int silk_bandwidth, int channels) -- GitLab