From 737898d5dcac390725cc7fa0c7478cebe56918d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Thu, 3 Mar 2022 11:43:26 +0200 Subject: [PATCH] common: Use unique_ptr for managing reception_flow memory --- include/uvgrtp/media_stream.hh | 4 ++-- src/media_stream.cc | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/uvgrtp/media_stream.hh b/include/uvgrtp/media_stream.hh index 2310d0e..6b2772d 100644 --- a/include/uvgrtp/media_stream.hh +++ b/include/uvgrtp/media_stream.hh @@ -342,8 +342,8 @@ namespace uvgrtp { uint32_t rtp_handler_key_; uint32_t zrtp_handler_key_; - /* RTP packet reception flow */ - uvgrtp::reception_flow *reception_flow_; + /* RTP packet reception flow. Dispatches packets to other components */ + std::unique_ptr reception_flow_; /* Media object associated with this media stream. */ uvgrtp::formats::media *media_; diff --git a/src/media_stream.cc b/src/media_stream.cc index 5645339..48658f1 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -201,7 +201,6 @@ rtp_error_t uvgrtp::media_stream::free_resources(rtp_error_t ret) } if (reception_flow_) { - delete reception_flow_; reception_flow_ = nullptr; } if (holepuncher_) @@ -230,7 +229,7 @@ rtp_error_t uvgrtp::media_stream::init() return free_resources(RTP_GENERIC_ERROR); } - reception_flow_ = new uvgrtp::reception_flow(); + reception_flow_ = std::unique_ptr (new uvgrtp::reception_flow()); rtp_ = std::shared_ptr (new uvgrtp::rtp(fmt_)); rtcp_ = std::shared_ptr (new uvgrtp::rtcp(rtp_, ctx_config_.flags)); @@ -252,7 +251,7 @@ rtp_error_t uvgrtp::media_stream::init(std::shared_ptr zrtp) return RTP_GENERIC_ERROR; } - reception_flow_ = new uvgrtp::reception_flow(); + reception_flow_ = std::unique_ptr (new uvgrtp::reception_flow()); rtp_ = std::shared_ptr (new uvgrtp::rtp(fmt_)); @@ -299,7 +298,7 @@ rtp_error_t uvgrtp::media_stream::add_srtp_ctx(uint8_t *key, uint8_t *salt) if ((flags_ & srtp_flags) != srtp_flags) return free_resources(RTP_NOT_SUPPORTED); - reception_flow_ = new uvgrtp::reception_flow(); + reception_flow_ = std::unique_ptr (new uvgrtp::reception_flow()); rtp_ = std::shared_ptr (new uvgrtp::rtp(fmt_));