diff options
author | James Almer <jamrial@gmail.com> | 2017-04-22 13:25:32 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2017-05-16 11:30:49 -0300 |
commit | d2c6bcdbf181daaea1f28d5f7bbe54e20fc46db6 (patch) | |
tree | b19afd305bf85e374c226458f8ef40b9b7434a60 | |
parent | 7f2eeb2c7478286f32c532b7c24e059cdbf59911 (diff) | |
download | ffmpeg-d2c6bcdbf181daaea1f28d5f7bbe54e20fc46db6.tar.gz |
avcodec/options: factorize avcodec_copy_context() cleanup code
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Tested-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 54a4c9b4e9a1524b1ac5d2be97c8042272402d0a)
-rw-r--r-- | libavcodec/options.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/libavcodec/options.c b/libavcodec/options.c index d8e3dbfa33..116d1ce4a6 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -187,6 +187,19 @@ void avcodec_free_context(AVCodecContext **pavctx) } #if FF_API_COPY_CONTEXT +static void copy_context_reset(AVCodecContext *avctx) +{ + av_opt_free(avctx); + av_freep(&avctx->rc_override); + av_freep(&avctx->intra_matrix); + av_freep(&avctx->inter_matrix); + av_freep(&avctx->extradata); + av_freep(&avctx->subtitle_header); + av_buffer_unref(&avctx->hw_frames_ctx); + avctx->subtitle_header_size = 0; + avctx->extradata_size = 0; +} + int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { const AVCodec *orig_codec = dest->codec; @@ -199,12 +212,7 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) return AVERROR(EINVAL); } - av_opt_free(dest); - av_freep(&dest->rc_override); - av_freep(&dest->intra_matrix); - av_freep(&dest->inter_matrix); - av_freep(&dest->extradata); - av_freep(&dest->subtitle_header); + copy_context_reset(dest); memcpy(dest, src, sizeof(*dest)); av_opt_copy(dest, src); @@ -263,15 +271,7 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; fail: - av_freep(&dest->subtitle_header); - av_freep(&dest->rc_override); - av_freep(&dest->intra_matrix); - av_freep(&dest->inter_matrix); - av_freep(&dest->extradata); - av_buffer_unref(&dest->hw_frames_ctx); - dest->subtitle_header_size = 0; - dest->extradata_size = 0; - av_opt_free(dest); + copy_context_reset(dest); return AVERROR(ENOMEM); } #endif |