diff --git a/src/manager.cpp b/src/manager.cpp index fbddb4b9b11b1d54c0b0cf8be0e91af5cbf49912..89cea7d97ead7cab566fcb23239d1b4c87f066dc 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -744,6 +744,8 @@ Manager::init(const std::string &config_file) setDhtLogLevel(); + // Manager can restart without being recreated (Unit tests) + // So only create the SipLink once pimpl_->sipLink_ = std::make_unique<SIPVoIPLink>(); check_rename(fileutils::get_cache_dir(PACKAGE_OLD), fileutils::get_cache_dir()); @@ -757,7 +759,7 @@ Manager::init(const std::string &config_file) bool no_errors = true; - // manager can restart without being recreated (android) + // manager can restart without being recreated (Unit tests) pimpl_->finished_ = false; try { @@ -850,6 +852,10 @@ Manager::finish() noexcept // Also, it must be called before pj_shutdown to avoid any problem pimpl_->ice_tf_.reset(); + // NOTE: sipLink_->shutdown() is needed because this will perform + // sipTransportBroker->shutdown(); which will call Manager::instance().sipVoIPLink() + // so the pointer MUST NOT be resetted at this point + pimpl_->sipLink_->shutdown(); pimpl_->sipLink_.reset(); pj_shutdown(); diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 357b87487f32dc7f6a4cacfd59c709e58b57b1df..4407179275ff82650db2038083b3345448eaaf18 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -627,9 +627,12 @@ SIPVoIPLink::SIPVoIPLink() : pool_(nullptr, pj_pool_release) JAMI_DBG("SIPVoIPLink@%p", this); } -SIPVoIPLink::~SIPVoIPLink() +SIPVoIPLink::~SIPVoIPLink() {} + +void +SIPVoIPLink::shutdown() { - JAMI_DBG("~SIPVoIPLink@%p", this); + JAMI_DBG("Shutdown SIPVoIPLink@%p...", this); // Remaining calls should not happen as possible upper callbacks // may be called and another instance of SIPVoIPLink can be re-created! @@ -647,7 +650,7 @@ SIPVoIPLink::~SIPVoIPLink() pool_.reset(); pj_caching_pool_destroy(&cp_); - JAMI_DBG("destroying SIPVoIPLink@%p", this); + JAMI_DBG("SIPVoIPLink@%p is shutdown", this); } std::shared_ptr<SIPAccountBase> diff --git a/src/sip/sipvoiplink.h b/src/sip/sipvoiplink.h index 3664bb527c91a01886173a6d9dcec5ff2b83fe7c..269ad7d77538cbbc53290b2aeb0efac58ee0cfd9 100644 --- a/src/sip/sipvoiplink.h +++ b/src/sip/sipvoiplink.h @@ -68,6 +68,11 @@ class SIPVoIPLink { SIPVoIPLink(); ~SIPVoIPLink(); + /** + * Destroy structures + */ + void shutdown(); + /** * Event listener. Each event send by the call manager is received and handled from here */