Commit 614ed3e6 authored by michael's avatar michael

Make sure priv_data is freed and codec is set to NULL in case of failure of avcodec_open().


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@20002 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent c1fe0583
...@@ -475,23 +475,20 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ...@@ -475,23 +475,20 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
if (((avctx->coded_width || avctx->coded_height) if (((avctx->coded_width || avctx->coded_height)
&& avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height)) && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height))
|| avctx->channels > SANE_NB_CHANNELS) { || avctx->channels > SANE_NB_CHANNELS) {
av_freep(&avctx->priv_data);
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto end; goto free_and_end;
} }
avctx->codec = codec; avctx->codec = codec;
if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){ if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
goto end; goto free_and_end;
} }
avctx->frame_number = 0; avctx->frame_number = 0;
if(avctx->codec->init){ if(avctx->codec->init){
ret = avctx->codec->init(avctx); ret = avctx->codec->init(avctx);
if (ret < 0) { if (ret < 0) {
av_freep(&avctx->priv_data); goto free_and_end;
avctx->codec= NULL;
goto end;
} }
} }
ret=0; ret=0;
...@@ -503,6 +500,10 @@ end: ...@@ -503,6 +500,10 @@ end:
(*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
} }
return ret; return ret;
free_and_end:
av_freep(&avctx->priv_data);
avctx->codec= NULL;
goto end;
} }
int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
......
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