From 5949eee4f4a8cab68efca4cebf03d4f090992337 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 21 Dec 2020 11:56:22 +0800 Subject: [PATCH] Keep resources when dispoing to avoid reuse addresses. --- trunk/src/app/srs_app_conn.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index 6ba8a62f5..ca963358c 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -272,6 +272,13 @@ void SrsResourceManager::do_clear() dispose(conn); } + + // We should free the resources when finished all disposing callbacks, + // which might cause context switch and reuse the freed addresses. + for (int i = 0; i < (int)copy.size(); i++) { + ISrsResource* conn = copy.at(i); + srs_freep(conn); + } } void SrsResourceManager::dispose(ISrsResource* c) @@ -315,8 +322,6 @@ void SrsResourceManager::dispose(ISrsResource* c) h->on_disposing(c); } - - srs_freep(c); } ISrsExpire::ISrsExpire()