Browse Source

Only dealloc SRTP if created

Paul-Louis Ageneau 5 years ago
parent
commit
36485110ef
2 changed files with 8 additions and 1 deletions
  1. 7 1
      src/dtlssrtptransport.cpp
  2. 1 0
      src/dtlssrtptransport.hpp

+ 7 - 1
src/dtlssrtptransport.cpp

@@ -59,7 +59,8 @@ DtlsSrtpTransport::DtlsSrtpTransport(std::shared_ptr<IceTransport> lower,
 DtlsSrtpTransport::~DtlsSrtpTransport() {
 DtlsSrtpTransport::~DtlsSrtpTransport() {
 	stop();
 	stop();
 
 
-	srtp_dealloc(mSrtp);
+	if (mCreated)
+		srtp_dealloc(mSrtp);
 }
 }
 
 
 bool DtlsSrtpTransport::send(message_ptr message) {
 bool DtlsSrtpTransport::send(message_ptr message) {
@@ -119,6 +120,9 @@ void DtlsSrtpTransport::incoming(message_ptr message) {
 }
 }
 
 
 void DtlsSrtpTransport::postHandshake() {
 void DtlsSrtpTransport::postHandshake() {
+	if (mCreated)
+		return;
+
 	srtp_policy_t inbound = {};
 	srtp_policy_t inbound = {};
 	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtp);
 	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtp);
 	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtcp);
 	srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&inbound.rtcp);
@@ -192,6 +196,8 @@ void DtlsSrtpTransport::postHandshake() {
 
 
 	if (srtp_err_status_t err = srtp_create(&mSrtp, policies))
 	if (srtp_err_status_t err = srtp_create(&mSrtp, policies))
 		throw std::runtime_error("SRTP create failed, status=" + to_string(static_cast<int>(err)));
 		throw std::runtime_error("SRTP create failed, status=" + to_string(static_cast<int>(err)));
+
+	mCreated = true;
 }
 }
 
 
 } // namespace rtc
 } // namespace rtc

+ 1 - 0
src/dtlssrtptransport.hpp

@@ -47,6 +47,7 @@ private:
 	message_callback mSrtpRecvCallback;
 	message_callback mSrtpRecvCallback;
 
 
 	srtp_t mSrtp;
 	srtp_t mSrtp;
+	bool mCreated = false;
 };
 };
 
 
 } // namespace rtc
 } // namespace rtc