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