From: James Zern Date: Thu, 27 Feb 2014 07:27:17 +0000 (-0800) Subject: y4m_video_source: fix memory leak X-Git-Tag: v1.4.0~2228^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f651bcb296f6ea15217056487c904689d57a0d0f;p=libvpx y4m_video_source: fix memory leak Begin() will be called twice with 2-pass encodes, invoking y4m_input_open which allocates memory; close the old instance first. Change-Id: Id252a21d286ca9ae998bd87599d43aeb8d7d77aa --- diff --git a/test/y4m_video_source.h b/test/y4m_video_source.h index 20d2be02b..74190432d 100644 --- a/test/y4m_video_source.h +++ b/test/y4m_video_source.h @@ -35,14 +35,11 @@ class Y4mVideoSource : public VideoSource { virtual ~Y4mVideoSource() { vpx_img_free(img_.get()); - y4m_input_close(&y4m_); - if (input_file_) - fclose(input_file_); + CloseSource(); } virtual void Begin() { - if (input_file_) - fclose(input_file_); + CloseSource(); input_file_ = OpenTestDataFile(file_name_); ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: " << file_name_; @@ -89,6 +86,15 @@ class Y4mVideoSource : public VideoSource { } protected: + void CloseSource() { + y4m_input_close(&y4m_); + y4m_ = y4m_input(); + if (input_file_ != NULL) { + fclose(input_file_); + input_file_ = NULL; + } + } + std::string file_name_; FILE *input_file_; testing::internal::scoped_ptr img_;