From c259590b26828374c70e5f52adffc3607144eddc Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 13 Feb 2015 15:12:52 +0300 Subject: [PATCH] Fix a memory leak in CvCapture_FFMPEG::close FFmpeg now requires that frames allocated with avcodec_alloc_frame are freed with avcodec_free_frame. (cherry picked from commit 77578d415f4d2b22a4ee1989ef0afda73c9d649b) --- modules/highgui/src/cap_ffmpeg_impl.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index 5f0207c..55a6fc0 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -292,7 +292,15 @@ void CvCapture_FFMPEG::close() } if( picture ) + { + // FFmpeg and Libav added avcodec_free_frame in different versions. +#if LIBAVCODEC_BUILD >= (LIBAVCODEC_VERSION_MICRO >= 100 \ + ? CALC_FFMPEG_VERSION(54, 59, 100) : CALC_FFMPEG_VERSION(54, 28, 0)) + avcodec_free_frame(&picture); +#else av_free(picture); +#endif + } if( video_st ) { -- 2.7.4