Prevent memory leak when receiving media loops at a page boundary

This commit is contained in:
Thulinma 2016-09-25 13:58:41 +02:00
parent 22cd84fcd5
commit f22d95b974

View file

@ -146,6 +146,7 @@ namespace Mist {
} }
if (!inserted){ if (!inserted){
FAIL_MSG("Could not insert page in track index. Aborting."); FAIL_MSG("Could not insert page in track index. Aborting.");
curPage[tid].master = true;//set this page for instant-deletion when we're done with it
return false; return false;
} }
} }
@ -260,6 +261,7 @@ namespace Mist {
static bool multiWrong = false; static bool multiWrong = false;
//Save the trackid of the track for easier access //Save the trackid of the track for easier access
unsigned long tid = pack.getTrackId(); unsigned long tid = pack.getTrackId();
//these checks were already done in bufferSinglePacket, but we check again just to be sure
if (myMeta.live && pack.getTime() > 0xFFFF0000 && !myMeta.tracks[tid].lastms){ if (myMeta.live && pack.getTime() > 0xFFFF0000 && !myMeta.tracks[tid].lastms){
return;//ignore bullshit timestamps return;//ignore bullshit timestamps
} }
@ -370,14 +372,17 @@ namespace Mist {
//Print a message about registering the page or not. //Print a message about registering the page or not.
if (!inserted) { if (!inserted) {
FAIL_MSG("Can't register page %lu on the metaPage of track %lu~>%lu, No empty spots left within 'should be' amount of slots", curPageNum[tid], tid, mapTid); FAIL_MSG("Can't register %lu on the metaPage of %s track %lu~>%lu, No empty spots left. Deleting.", curPageNum[tid], streamName.c_str(), tid, mapTid);
//Since the buffer can't see it - we should delete it ourselves, now.
curPage[tid].master = true;
} else { } else {
HIGH_MSG("Succesfully registered page %lu on the metaPage of track %lu~>%lu.", curPageNum[tid], tid, mapTid); HIGH_MSG("Registered %lu on the metaPage of %s track %lu~>%lu.", curPageNum[tid], streamName.c_str(), tid, mapTid);
#if defined(__CYGWIN__) || defined(_WIN32)
IPC::preservePage(curPage[tid].name);
#endif
} }
//Close our link to the page. This will NOT destroy the shared page, as we've set master to false upon construction //Close our link to the page. This will NOT destroy the shared page, as we've set master to false upon construction
#if defined(__CYGWIN__) || defined(_WIN32) //Note: if there was a registering failure above, this WILL destroy the shared page, to prevent a memory leak
IPC::preservePage(curPage[tid].name);
#endif
curPage.erase(tid); curPage.erase(tid);
curPageNum.erase(tid); curPageNum.erase(tid);
} }
@ -457,6 +462,19 @@ namespace Mist {
} }
} }
} }
//For live streams, ignore packets that make no sense
//This also happens in bufferNext, with the same rules
if (myMeta.live){
if (packet.getTime() > 0xFFFF0000 && !myMeta.tracks[tid].lastms){
return;//ignore bullshit timestamps
}
if (packet.getTime() < myMeta.tracks[tid].lastms){
HIGH_MSG("Wrong order on track %lu ignored: %lu < %lu", tid, packet.getTime(), myMeta.tracks[tid].lastms);
return;
}
}
//Determine if we need to open the next page //Determine if we need to open the next page
int nextPageNum = -1; int nextPageNum = -1;
if (isKeyframe && trackState[tid] == FILL_ACC) { if (isKeyframe && trackState[tid] == FILL_ACC) {
@ -501,7 +519,11 @@ namespace Mist {
bufferFinalize(tid, myMeta); bufferFinalize(tid, myMeta);
} }
//Open the new page //Open the new page
bufferStart(tid, nextPageNum, myMeta); if (!bufferStart(tid, nextPageNum, myMeta)){
//if this fails, return instantly without actually buffering the packet
WARN_MSG("Dropping packet %s:%llu@%llu", streamName.c_str(), tid, packet.getTime());
return;
}
} }
//Buffer the packet //Buffer the packet
bufferNext(packet, myMeta); bufferNext(packet, myMeta);