lavc: make avcodec_close() work properly on unopened codecs.

I.e. free the priv_data and other stuff allocated in
avcodec_alloc_context3() and not segfault.

(cherry picked from commit 0e72ad95f9)
This commit is contained in:
Anton Khirnov
2012-01-29 12:17:30 +01:00
committed by Reinhard Tartler
parent 350d06d63f
commit bafd38a352
2 changed files with 22 additions and 9 deletions

View File

@@ -1281,14 +1281,17 @@ av_cold int avcodec_close(AVCodecContext *avctx)
return -1;
}
if (HAVE_THREADS && avctx->thread_opaque)
ff_thread_free(avctx);
if (avctx->codec && avctx->codec->close)
avctx->codec->close(avctx);
avcodec_default_free_buffers(avctx);
avctx->coded_frame = NULL;
av_freep(&avctx->internal);
if (avctx->codec && avctx->codec->priv_class)
if (avcodec_is_open(avctx)) {
if (HAVE_THREADS && avctx->thread_opaque)
ff_thread_free(avctx);
if (avctx->codec && avctx->codec->close)
avctx->codec->close(avctx);
avcodec_default_free_buffers(avctx);
avctx->coded_frame = NULL;
av_freep(&avctx->internal);
}
if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
av_opt_free(avctx->priv_data);
av_opt_free(avctx);
av_freep(&avctx->priv_data);