fix a memory leak in KaxReferenceBlock when an internal KaxBlockBlob was created

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libmatroska@546 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme 2010-09-10 08:39:15 +00:00
parent f1349f9639
commit 697ce73358
3 changed files with 242 additions and 221 deletions

View File

@ -6,6 +6,7 @@ New 1.1.0 version:
- add the possibility for a DataBuffer class to use its own internal memory
- KaxCues::AddBlockGroup() was removed as it's broken beyond repair
- add KaxTrackOperation and related elements for combined stereo/3D tracks or joined virtual tracks
- fix a memory leak in KaxReferenceBlock when an internal KaxBlockBlob was created
2010-06-04 robux4/mosu
New 1.0.0 version:

View File

@ -55,6 +55,7 @@ DECLARE_MKX_UINTEGER(KaxReferencePriority)
*/
DECLARE_MKX_SINTEGER_CONS(KaxReferenceBlock)
public:
~KaxReferenceBlock();
/*!
\brief override this method to compute the timecode value
*/
@ -70,6 +71,8 @@ DECLARE_MKX_SINTEGER_CONS(KaxReferenceBlock)
const KaxBlockGroup * ParentBlock;
void SetReferencedTimecode(int64 refTimecode) {*static_cast<EbmlSInteger*>(this) = refTimecode; bTimecodeSet = true;};
bool bTimecodeSet;
bool bOurBlob;
void FreeBlob();
};
#if MATROSKA_VERSION >= 2

View File

@ -84,9 +84,22 @@ RefdBlock(NULL)
KaxReferenceBlock::KaxReferenceBlock(const KaxReferenceBlock & ElementToClone)
:EbmlSInteger(ElementToClone)
,bTimecodeSet(ElementToClone.bTimecodeSet)
,bOurBlob(false)
{
}
KaxReferenceBlock::~KaxReferenceBlock()
{
FreeBlob();
}
void KaxReferenceBlock::FreeBlob()
{
if (bOurBlob && RefdBlock!=NULL)
delete RefdBlock;
RefdBlock = NULL;
}
filepos_t KaxReferenceBlock::UpdateSize(bool bSaveDefault, bool bForceRender)
{
if (!bTimecodeSet) {
@ -103,15 +116,19 @@ void KaxReferenceBlock::SetReferencedBlock(const KaxBlockBlob * aRefdBlock)
{
assert(RefdBlock == NULL);
assert(aRefdBlock != NULL);
FreeBlob();
RefdBlock = aRefdBlock;
bOurBlob = true;
SetValueIsSet();
}
void KaxReferenceBlock::SetReferencedBlock(const KaxBlockGroup & aRefdBlock)
{
FreeBlob();
KaxBlockBlob *block_blob = new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE);
block_blob->SetBlockGroup(*const_cast<KaxBlockGroup*>(&aRefdBlock));
RefdBlock = block_blob;
bOurBlob = true;
SetValueIsSet();
}