[FFmpeg-cvslog] avcodec/options: do a more thorough clean up in avcodec_copy_context()

James Almer git at videolan.org
Fri May 12 06:58:23 EEST 2017


ffmpeg | branch: release/3.2 | James Almer <jamrial at gmail.com> | Mon Apr 24 14:53:47 2017 -0300| [65add3a8184d080be147ac4a80fa29b104a6e7d5] | committer: James Almer

avcodec/options: do a more thorough clean up in avcodec_copy_context()

Free coded_frame and coded_side_data to prevent potential leaks.

Reviewed-by: Aaron Levinson <alevinsn at aracnet.com>
Tested-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: James Almer <jamrial at gmail.com>
(cherry picked from commit cac8de2da5c4935773128335c11b806faa73e19d)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=65add3a8184d080be147ac4a80fa29b104a6e7d5
---

 libavcodec/options.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/options.c b/libavcodec/options.c
index 116d1ce4a6..e124fb442e 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -189,14 +189,25 @@ void avcodec_free_context(AVCodecContext **pavctx)
 #if FF_API_COPY_CONTEXT
 static void copy_context_reset(AVCodecContext *avctx)
 {
+    int i;
+
     av_opt_free(avctx);
+#if FF_API_CODED_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+    av_frame_free(&avctx->coded_frame);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     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);
+    for (i = 0; i < avctx->nb_coded_side_data; i++)
+        av_freep(&avctx->coded_side_data[i].data);
+    av_freep(&avctx->coded_side_data);
     avctx->subtitle_header_size = 0;
+    avctx->nb_coded_side_data = 0;
     avctx->extradata_size = 0;
 }
 
@@ -237,11 +248,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
     /* reallocate values that should be allocated separately */
     dest->extradata       = NULL;
+    dest->coded_side_data = NULL;
     dest->intra_matrix    = NULL;
     dest->inter_matrix    = NULL;
     dest->rc_override     = NULL;
     dest->subtitle_header = NULL;
     dest->hw_frames_ctx   = NULL;
+    dest->nb_coded_side_data = 0;
 
 #define alloc_and_copy_or_fail(obj, size, pad) \
     if (src->obj && size > 0) { \



More information about the ffmpeg-cvslog mailing list