From 927f3b9cfdbad6ba8744b905ce48adb9e804a652 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Wed, 27 Jan 2016 14:05:16 -0500 Subject: [PATCH] transport: catch std::runtime_error When there is no internet connection, an error is thrown in IceTransport constructor. This destroys what has already been initialized including the thread. Change-Id: I81b6ec1f52b9312a1d6ea24c5f55dfa94da7e877 Tuleap: #189 Tuleap: #258 --- src/ice_transport.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index 06bec80115..f0e7b7ba07 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -170,18 +170,21 @@ IceTransport::IceTransport(const char* name, int component_count, bool master, TRY( pj_timer_heap_create(pool_.get(), 100, &config_.stun_cfg.timer_heap) ); TRY( pj_ioqueue_create(pool_.get(), IOQUEUE_MAX_HANDLES, &config_.stun_cfg.ioqueue) ); + pj_ice_strans* icest = nullptr; + pj_status_t status = pj_ice_strans_create(name, &config_, component_count, + this, &icecb, &icest); + + if (status != PJ_SUCCESS || icest == nullptr) { + throw std::runtime_error("pj_ice_strans_create() failed"); + } + + // Must be created after any potential failure thread_ = std::thread([this]{ register_thread(); while (not threadTerminateFlags_) { handleEvents(500); // limit polling to 500ms } }); - - pj_ice_strans* icest = nullptr; - pj_status_t status = pj_ice_strans_create(name, &config_, component_count, - this, &icecb, &icest); - if (status != PJ_SUCCESS || icest == nullptr) - throw std::runtime_error("pj_ice_strans_create() failed"); } IceTransport::~IceTransport() -- GitLab