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.