ffmpeg: fix memory leak if writer is initialized multiple times.

This commit is contained in:
Adrien Destugues
2020-09-05 18:38:25 +02:00
parent 3cf5015980
commit 9a6a570ac9
@@ -93,6 +93,7 @@ AVFormatWriter::StreamCookie::StreamCookie(AVFormatContext* context,
AVFormatWriter::StreamCookie::~StreamCookie() AVFormatWriter::StreamCookie::~StreamCookie()
{ {
// fStream is freed automatically when the codec context is closed
} }
@@ -392,6 +393,7 @@ AVFormatWriter::Init(const media_file_format* fileFormat)
{ {
TRACE("AVFormatWriter::Init()\n"); TRACE("AVFormatWriter::Init()\n");
if (fIOContext == NULL) {
uint8* buffer = static_cast<uint8*>(av_malloc(kIOBufferSize)); uint8* buffer = static_cast<uint8*>(av_malloc(kIOBufferSize));
if (buffer == NULL) if (buffer == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -408,6 +410,7 @@ AVFormatWriter::Init(const media_file_format* fileFormat)
// Setup I/O hooks. This seems to be enough. // Setup I/O hooks. This seems to be enough.
fFormatContext->pb = fIOContext; fFormatContext->pb = fIOContext;
}
// Set the AVOutputFormat according to fileFormat... // Set the AVOutputFormat according to fileFormat...
fFormatContext->oformat = av_guess_format(fileFormat->short_name, fFormatContext->oformat = av_guess_format(fileFormat->short_name,