avctx->priv_data = av_mallocz(codec->priv_data_size);
if (!avctx->priv_data) {
ret = AVERROR(ENOMEM);
- goto end;
+ goto free_and_end;
}
if (codec->priv_class) {
*(const AVClass **)avctx->priv_data = codec->priv_class;
|| avci->frame_thread_encoder)) {
ret = avctx->codec->init(avctx);
if (ret < 0) {
+ codec_init_ok = -1;
goto free_and_end;
}
codec_init_ok = 1;
return ret;
free_and_end:
if (avctx->codec && avctx->codec->close &&
- (codec_init_ok ||
- (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP)))
+ (codec_init_ok > 0 || (codec_init_ok < 0 &&
+ avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP)))
avctx->codec->close(avctx);
if (HAVE_THREADS && avci->thread_ctx)
ff_thread_free(avctx);
- if (codec->priv_class && codec->priv_data_size)
+ if (codec->priv_class && avctx->priv_data)
av_opt_free(avctx->priv_data);
av_opt_free(avctx);
+ if (av_codec_is_encoder(avctx->codec)) {
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
- av_frame_free(&avctx->coded_frame);
+ av_frame_free(&avctx->coded_frame);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
+ av_freep(&avctx->extradata);
+ avctx->extradata_size = 0;
+ }
av_dict_free(&tmp);
av_freep(&avctx->priv_data);
av_freep(&avctx->subtitle_header);
- if (avci) {
- av_frame_free(&avci->to_free);
- av_frame_free(&avci->compat_decode_frame);
- av_frame_free(&avci->buffer_frame);
- av_packet_free(&avci->compat_encode_packet);
- av_packet_free(&avci->buffer_pkt);
- av_packet_free(&avci->last_pkt_props);
- av_packet_free(&avci->ds.in_pkt);
- av_frame_free(&avci->es.in_frame);
- av_bsf_free(&avci->bsf);
+ av_frame_free(&avci->to_free);
+ av_frame_free(&avci->compat_decode_frame);
+ av_frame_free(&avci->buffer_frame);
+ av_packet_free(&avci->compat_encode_packet);
+ av_packet_free(&avci->buffer_pkt);
+ av_packet_free(&avci->last_pkt_props);
- av_buffer_unref(&avci->pool);
- }
+ av_packet_free(&avci->ds.in_pkt);
+ av_frame_free(&avci->es.in_frame);
+ av_bsf_free(&avci->bsf);
+
+ av_buffer_unref(&avci->pool);
av_freep(&avci);
avctx->internal = NULL;
avctx->codec = NULL;
return "unknown_codec";
}
+#if FF_API_TAG_STRING
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
{
int i, len, ret = 0;
}
return ret;
}
+#endif
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
{