ref: e03af4423dcaef209627ca028c66973b5cc3c647
parent: a40721a92e4b675c476b93e3f15d59a803ed24a0
author: Gregory Maxwell <[email protected]>
date: Sun Sep 4 00:43:11 EDT 2011
Prevent double free on encoder/decoder init failure.
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -88,10 +88,9 @@
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 @@
/* 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)
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -162,8 +162,7 @@
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 @@
/* 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 @@
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)