Browse Source

Fixed the dereferencing of a nullptr

root 4 years ago
parent
commit
dc91d2cb6d
1 changed files with 14 additions and 12 deletions
  1. 14 12
      src/track.cpp

+ 14 - 12
src/track.cpp

@@ -142,18 +142,20 @@ void Track::incoming(message_ptr message) {
 
 
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 	mRtcpHandler = std::move(handler);
 	mRtcpHandler = std::move(handler);
-	mRtcpHandler->onOutgoing([&](const rtc::message_ptr& message) {
-        #if RTC_ENABLE_MEDIA
-                auto transport = mDtlsSrtpTransport.lock();
-                if (!transport)
-                    throw std::runtime_error("Track transport is not open");
-
-                return transport->sendMedia(message);
-        #else
-                PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
-            return false;
-        #endif
-	});
+	if (mRtcpHandler) {
+		mRtcpHandler->onOutgoing([&](const rtc::message_ptr& message) {
+		#if RTC_ENABLE_MEDIA
+			auto transport = mDtlsSrtpTransport.lock();
+			if (!transport)
+			    throw std::runtime_error("Track transport is not open");
+
+			return transport->sendMedia(message);
+		#else
+			PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
+		    return false;
+		#endif
+		});
+	}
 }
 }
 
 
 bool Track::requestKeyframe() {
 bool Track::requestKeyframe() {