Prevent double free on encoder/decoder init failure.

This commit is contained in:
Gregory Maxwell 2011-09-04 04:43:11 -04:00
parent a40721a92e
commit e03af4423d
2 changed files with 9 additions and 20 deletions

View file

@ -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)

View file

@ -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)