From 689c1814a54496e11517a8577d03c07887430066 Mon Sep 17 00:00:00 2001 From: Alexander Reshetnikov Date: Fri, 27 Apr 2012 19:23:26 +0000 Subject: [PATCH] Fixed VideoCapture memory leak (bug #1481) --- modules/highgui/src/cap_ffmpeg_impl.hpp | 6 ++++++ modules/highgui/src/cap_ffmpeg_impl_v2.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index c27cd022c7..672396888a 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -468,6 +468,12 @@ bool CvCapture_FFMPEG::grabFrame() picture_pts = packet.pts; valid = 1; } + + if (packet.data) + { + av_free_packet(&packet); + packet.data = NULL; + } } // return if we have a new picture or not diff --git a/modules/highgui/src/cap_ffmpeg_impl_v2.hpp b/modules/highgui/src/cap_ffmpeg_impl_v2.hpp index 97e26cb09c..97c7d5329e 100755 --- a/modules/highgui/src/cap_ffmpeg_impl_v2.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl_v2.hpp @@ -463,6 +463,12 @@ bool CvCapture_FFMPEG::grabFrame() if (count_errs > max_number_of_attempts) break; } + + if (packet.data) + { + av_free_packet (&packet); + packet.data = NULL; + } } if( valid && first_frame_number < 0 )