freeMXF.org
http://freemxf.org/forum/

Memory leak in GCWriter::AddEssenceData() (+fix)
http://freemxf.org/forum/viewtopic.php?f=2&t=198
Page 1 of 1

Author:  Tjoppen [ Wed Mar 03, 2010 4:05 pm ]
Post subject:  Memory leak in GCWriter::AddEssenceData() (+fix)

I just noticed GCWriter::AddEssenceData() leaks memory if called more than once per stream without a prior call to GCWriter::Flush(). The culprit is the fact that all variants of the function allocate a buffer (UInt8 *Buffer) that isn't freed when/if WriteQueue.insert() fails.
The solution is simple: before allocating Buffer check whether WriteQueue already has an entry for the current stream. If so, bail out:

Code:
if(WriteQueue.find(Stream->WriteOrder) != WriteQueue.end())
    return;

// Set up a new buffer big enough for the key, a huge BER length and the data
UInt8 *Buffer = new UInt8[(size_t)(16 + 9 + Size)];


Could probably use some kind of error message, but otherwise shuts valgrind up.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/