Skip to content

Commit

Permalink
[core] Added mutex protection and null check for removeFromGroup (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris committed Oct 21, 2020
1 parent 1e6e5ac commit bda3383
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions srtcore/api.cpp
Expand Up @@ -3027,26 +3027,34 @@ int CUDT::removeSocketFromGroup(SRTSOCKET socket)
if (!s->m_IncludedGroup)
return APIError(MJ_NOTSUP, MN_INVAL, 0);

ScopedLock grd (s->m_ControlLock);
s->removeFromGroup(false);
return 0;
}

void CUDTSocket::removeFromGroup(bool broken)
{
m_IncludedGroup->remove(m_SocketID);
CUDTGroup* pg = 0;
{
ScopedLock grd (m_ControlLock);
pg = m_IncludedGroup;
m_IncludedIter = CUDTGroup::gli_NULL();
m_IncludedGroup = NULL;
}

// Another facility could have deleted it in the meantime.
if (!pg)
return;

pg->remove(m_SocketID);
if (broken)
{
// Activate the SRT_EPOLL_UPDATE event on the group
// if it was because of a socket that was earlier connected
// and became broken. This is not to be sent in case when
// it is a failure during connection, or the socket was
// explicitly removed from the group.
m_IncludedGroup->activateUpdateEvent();
pg->activateUpdateEvent();
}

m_IncludedIter = CUDTGroup::gli_NULL();
m_IncludedGroup = NULL;
}

SRTSOCKET CUDT::getGroupOfSocket(SRTSOCKET socket)
Expand Down

0 comments on commit bda3383

Please sign in to comment.