Protect access to shared list of SRTP sessions.

This is a follow up to https://webrtc-codereview.appspot.com/47319004/
and locks access to the static list of SRTP sessions to prevent potential
race conditions.

BUG=4042
R=juberti@google.com

Review URL: https://webrtc-codereview.appspot.com/52609004

Cr-Commit-Position: refs/heads/master@{#9326}
This commit is contained in:
Joachim Bauch
2015-05-29 01:20:52 +02:00
parent 9e3cb336d4
commit e70028e43f

View File

@ -474,6 +474,8 @@ bool SrtpFilter::ParseKeyParams(const std::string& key_params,
#ifdef HAVE_SRTP
bool SrtpSession::inited_ = false;
// This lock protects SrtpSession::inited_ and SrtpSession::sessions_.
rtc::GlobalLockPod SrtpSession::lock_;
SrtpSession::SrtpSession()
@ -482,12 +484,18 @@ SrtpSession::SrtpSession()
rtcp_auth_tag_len_(0),
srtp_stat_(new SrtpStat()),
last_send_seq_num_(-1) {
sessions()->push_back(this);
{
rtc::GlobalLockScope ls(&lock_);
sessions()->push_back(this);
}
SignalSrtpError.repeat(srtp_stat_->SignalSrtpError);
}
SrtpSession::~SrtpSession() {
sessions()->erase(std::find(sessions()->begin(), sessions()->end(), this));
{
rtc::GlobalLockScope ls(&lock_);
sessions()->erase(std::find(sessions()->begin(), sessions()->end(), this));
}
if (session_) {
srtp_dealloc(session_);
}
@ -766,6 +774,8 @@ void SrtpSession::HandleEvent(const srtp_event_data_t* ev) {
}
void SrtpSession::HandleEventThunk(srtp_event_data_t* ev) {
rtc::GlobalLockScope ls(&lock_);
for (std::list<SrtpSession*>::iterator it = sessions()->begin();
it != sessions()->end(); ++it) {
if ((*it)->session_ == ev->session) {