diff options
author | Anton Khirnov <anton@khirnov.net> | 2012-01-29 12:17:30 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2012-01-31 07:56:21 +0100 |
commit | 0e72ad95f9fef6a6b8ae55e47339a5c40526502f (patch) | |
tree | bbe8447376195376bb714d6075272937cebb9370 /libavcodec/utils.c | |
parent | af08d9aeea870de017139f7b1c44b7d816cf8e56 (diff) | |
download | ffmpeg-0e72ad95f9fef6a6b8ae55e47339a5c40526502f.tar.gz |
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.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 3ee6b09f74..9cdae22305 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1267,14 +1267,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); |