From 8a1f3038407f37a3e212c77e86630533dce8c705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Fri, 6 Sep 2013 23:36:58 +0200 Subject: [PATCH] ffmpeg: release the reader context on destruction. * avformat_open_input() is to be balanced with a avformat_close_input(). * should help with #9945. --- src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp index 23b0b66815..7531060629 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp @@ -238,10 +238,12 @@ StreamBase::StreamBase(BPositionIO* source, BLocker* sourceLock, StreamBase::~StreamBase() { - av_free(fIOContext->buffer); - av_free(fIOContext); + if (fContext != NULL) + avformat_close_input(&fContext); av_free_packet(&fPacket); av_free(fContext); + av_free(fIOContext->buffer); + av_free(fIOContext); } @@ -263,6 +265,7 @@ StreamBase::Open() _Seek); if (fIOContext == NULL) { TRACE("StreamBase::Open() - avio_alloc_context() failed!\n"); + av_free(buffer); return B_ERROR; } @@ -273,6 +276,9 @@ StreamBase::Open() if (avformat_open_input(&fContext, "", NULL, NULL) < 0) { TRACE("StreamBase::Open() - avformat_open_input() failed!\n"); // avformat_open_input() frees the context in case of failure + fContext = NULL; + av_free(fIOContext); + fIOContext = NULL; return B_NOT_SUPPORTED; } @@ -1772,5 +1778,3 @@ AVFormatReader::GetNextChunk(void* _cookie, const void** chunkBuffer, Stream* cookie = reinterpret_cast(_cookie); return cookie->GetNextChunk(chunkBuffer, chunkSize, mediaHeader); } - -