diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index de87fbb83..76a59eb95 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -1081,7 +1081,9 @@ SrsRtcServer::~SrsRtcServer() srs_freep(trd); srs_cond_destroy(cond); - clear(); + + free_messages(mmhdrs); + mmhdrs.clear(); } srs_error_t SrsRtcServer::initialize() @@ -1335,10 +1337,10 @@ srs_error_t SrsRtcServer::send_and_free_messages(srs_netfd_t stfd, const vector< return err; } -void SrsRtcServer::clear() +void SrsRtcServer::free_messages(vector& hdrs) { - for (int i = 0; i < (int)mmhdrs.size(); i++) { - msghdr* hdr = &mmhdrs[i].msg_hdr; + for (int i = 0; i < (int)hdrs.size(); i++) { + msghdr* hdr = &hdrs[i].msg_hdr; for (int j = (int)hdr->msg_iovlen - 1; j >= 0 ; j--) { iovec* iov = hdr->msg_iov + j; char* data = (char*)iov->iov_base; @@ -1346,8 +1348,6 @@ void SrsRtcServer::clear() srs_freep(iov); } } - - mmhdrs.clear(); } srs_error_t SrsRtcServer::cycle() @@ -1396,13 +1396,7 @@ srs_error_t SrsRtcServer::cycle() srs_trace("-> RTC SEND %d msgs, by sendmmsg %d", mhdrs.size(), max_sendmmsg); } - for (int i = 0; i < (int)mhdrs.size(); i++) { - msghdr* hdr = &mhdrs[i].msg_hdr; - for (int i = 0; i < (int)hdr->msg_iovlen; i++) { - iovec* iov = hdr->msg_iov + i; - delete (char*)iov->iov_base; - } - } + free_messages(mhdrs); } return err; diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index 2618613a1..b4351d448 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -256,7 +256,7 @@ public: // Internal only. public: srs_error_t send_and_free_messages(srs_netfd_t stfd, const std::vector& msgs); - void clear(); + void free_messages(std::vector& hdrs); virtual srs_error_t cycle(); };