Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed fallback for memory allocation errors #1459

Merged
merged 5 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2499,11 +2499,7 @@ void CUDTUnited::removeSocket(const SRTSOCKET u)
// being currently done in the queues, if any.
mx.m_pSndQueue->setClosing();
mx.m_pRcvQueue->setClosing();
delete mx.m_pSndQueue;
delete mx.m_pRcvQueue;
mx.m_pChannel->close();
delete mx.m_pTimer;
delete mx.m_pChannel;
mx.destroy();
m_mMultiplexer.erase(m);
}
}
Expand Down Expand Up @@ -2562,16 +2558,16 @@ void CUDTUnited::updateMux(
m.m_bReusable = s->m_pUDT->m_bReuseAddr;
m.m_iID = s->m_SocketID;

m.m_pChannel = new CChannel();
m.m_pChannel->setIpTTL(s->m_pUDT->m_iIpTTL);
m.m_pChannel->setIpToS(s->m_pUDT->m_iIpToS);
m.m_pChannel->setSndBufSize(s->m_pUDT->m_iUDPSndBufSize);
m.m_pChannel->setRcvBufSize(s->m_pUDT->m_iUDPRcvBufSize);
if (s->m_pUDT->m_iIpV6Only != -1)
m.m_pChannel->setIpV6Only(s->m_pUDT->m_iIpV6Only);

try
{
m.m_pChannel = new CChannel();
m.m_pChannel->setIpTTL(s->m_pUDT->m_iIpTTL);
m.m_pChannel->setIpToS(s->m_pUDT->m_iIpToS);
m.m_pChannel->setSndBufSize(s->m_pUDT->m_iUDPSndBufSize);
m.m_pChannel->setRcvBufSize(s->m_pUDT->m_iUDPRcvBufSize);
if (s->m_pUDT->m_iIpV6Only != -1)
m.m_pChannel->setIpV6Only(s->m_pUDT->m_iIpV6Only);

if (udpsock)
{
// In this case, addr contains the address
Expand Down Expand Up @@ -2617,15 +2613,13 @@ void CUDTUnited::updateMux(
}
catch (CUDTException& e)
{
m.m_pChannel->close();
delete m.m_pChannel;
throw;
m.destroy();
throw;
}
catch (...)
{
m.m_pChannel->close();
delete m.m_pChannel;
throw CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0);
m.destroy();
throw CUDTException(MJ_SYSTEMRES, MN_MEMORY, 0);
}

HLOGF(mglog.Debug,
Expand Down
15 changes: 15 additions & 0 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,3 +1682,18 @@ void CRcvQueue::storePkt(int32_t id, CPacket *pkt)
i->second.push(pkt);
}
}


void CMultiplexer::destroy()
{
// Reverse order of the assigned
delete m_pRcvQueue;
delete m_pSndQueue;
delete m_pTimer;

if (m_pChannel)
{
m_pChannel->close();
delete m_pChannel;
}
}
12 changes: 12 additions & 0 deletions srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,18 @@ struct CMultiplexer
bool m_bReusable; // if this one can be shared with others

int m_iID; // multiplexer ID

// Constructor should reset all pointers to NULL
// to prevent dangling pointer when checking for memory alloc fails
CMultiplexer()
: m_pSndQueue(NULL)
, m_pRcvQueue(NULL)
, m_pChannel(NULL)
, m_pTimer(NULL)
{
}

void destroy();
};

#endif