1
0
Fork 0

MatroskaParser: cleaner way of ensuring all data blocks are free'ed at all times

This commit is contained in:
Hendrik Leppkes 2019-09-12 22:59:33 +02:00
parent 12536d259a
commit 6ece5d7a59
Signed by: hendrik
GPG Key ID: 846079A4B0A7C1B5
1 changed files with 6 additions and 19 deletions

View File

@ -515,11 +515,12 @@ static struct QueueEntry *QAlloc(MatroskaFile *mf) {
errorjmp(mf,"Ouf of memory");
qe = *qep;
qe->Data = NULL;
for (i=0;i<QSEGSIZE-1;++i)
for (i=0;i<QSEGSIZE-1;++i) {
qe[i].next = qe+i+1;
qe[i].Data = NULL;
}
qe[QSEGSIZE-1].next = NULL;
qe[QSEGSIZE-1].Data = NULL;
mf->QFreeList = qe;
}
@ -2346,7 +2347,6 @@ static void parseBlockGroup(MatroskaFile *mf,ulonglong toplen,ulonglong timecode
unsigned nframes = 0,i;
unsigned *sizes;
signed short block_timecode;
jmp_buf jb;
if (blockex)
goto blockex;
@ -2441,16 +2441,6 @@ found:
break;
}
// we need to free the packet in case of errors here
memcpy(&jb, &mf->jb, sizeof(jb));
if (setjmp(mf->jb)) {
QFree(mf, qe);
// jump to the top level handler
memcpy(&mf->jb, &jb, sizeof(jb));
longjmp(mf->jb, 1);
}
v = filepos(mf);
qf = NULL;
for (i=0;i<nframes;++i) {
@ -2476,8 +2466,6 @@ found:
v += sizes[i];
}
memcpy(&mf->jb, &jb, sizeof(jb));
// we want to still load these bytes into cache
for (v = filepos(mf) & ~0x3fff; v < len + dpos; v += 0x4000)
mf->cache->read(mf->cache,v,NULL,0); // touch page
@ -3282,14 +3270,13 @@ void mkv_Close(MatroskaFile *mf) {
if (mf==NULL)
return;
EmptyQueues(mf);
for (i=0;i<mf->nTracks;++i)
mf->cache->memfree(mf->cache,mf->Tracks[i]);
mf->cache->memfree(mf->cache,mf->Tracks);
for (i=0;i<mf->nQBlocks;++i) {
mf->cache->memfree(mf->cache,mf->QBlocks[i]->Data);
for (j=0;j<QSEGSIZE;j++)
mf->cache->memfree(mf->cache, mf->QBlocks[i][j].Data);
mf->cache->memfree(mf->cache,mf->QBlocks[i]);
}
mf->cache->memfree(mf->cache,mf->QBlocks);