From c4fc51a24b615b7eaab519779a528e1eb5a0bbca Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Wed, 22 Mar 2017 22:35:27 -0400 Subject: [PATCH] upnp: fix early crash by std::terminate In NAP-PMP implementation, a std::thread member of UPnPContext class is placed before member used by the thread. This thread is run during the class initialization (ctor). So the thread can start and access to these members when they are not initialized. The consequence is a std::terminate() call causing the stop of daemon. Fix that by moving the thread member after *ALL* used members. Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Change-Id: Ibb7334e653a9c80c566ffc3944c93a6ef64e0a8b --- src/upnp/upnp_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upnp/upnp_context.h b/src/upnp/upnp_context.h index b5fb188bd8..843f9fe634 100644 --- a/src/upnp/upnp_context.h +++ b/src/upnp/upnp_context.h @@ -158,11 +158,11 @@ private: uint16_t chooseRandomPort(const IGD& igd, PortType type); #if HAVE_LIBNATPMP - std::thread pmpThread_ {}; std::mutex pmpMutex_ {}; std::condition_variable pmpCv_ {}; std::shared_ptr<PMPIGD> pmpIGD_ {}; std::atomic_bool pmpRun_ {true}; + std::thread pmpThread_ {}; void PMPsearchForIGD(const std::shared_ptr<PMPIGD>& pmp_igd, natpmp_t& natpmp); void PMPaddPortMapping(const PMPIGD& pmp_igd, natpmp_t& natpmp, GlobalMapping& mapping, bool remove=false) const; -- GitLab