Merge pull request #229 from anonymouspage/cg3protocol-initialize-thread-vars

cg3protocol: fix crash/default initialize std::thread pointers
This commit is contained in:
LX3JL 2023-03-01 18:39:31 +01:00 committed by GitHub
commit d14dc22fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 11 deletions

View file

@ -79,9 +79,17 @@ bool CG3Protocol::Init(void)
if (ok)
{
// start helper threads
m_pPresenceThread = new std::thread(PresenceThread, this);
m_pPresenceThread = new std::thread(ConfigThread, this);
m_pPresenceThread = new std::thread(IcmpThread, this);
try
{
m_pPresenceThread = new std::thread(PresenceThread, this);
m_pConfigThread = new std::thread(ConfigThread, this);
m_pIcmpThread = new std::thread(IcmpThread, this);
}
catch (const std::system_error& e)
{
ok = false;
// ... threads will be cleaned up on the call to ::Close()
}
}
#endif
@ -94,25 +102,25 @@ bool CG3Protocol::Init(void)
void CG3Protocol::Close(void)
{
if (m_pPresenceThread != NULL)
if (m_pPresenceThread)
{
m_pPresenceThread->join();
delete m_pPresenceThread;
m_pPresenceThread = NULL;
m_pPresenceThread = nullptr;
}
if (m_pConfigThread != NULL)
if (m_pConfigThread)
{
m_pConfigThread->join();
delete m_pConfigThread;
m_pConfigThread = NULL;
m_pConfigThread = nullptr;
}
if (m_pIcmpThread != NULL)
if (m_pIcmpThread)
{
m_pIcmpThread->join();
delete m_pIcmpThread;
m_pIcmpThread = NULL;
m_pIcmpThread = nullptr;
}
}
@ -600,7 +608,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// drop if invalid module
delete Header;
g_Reflector.ReleaseClients();
return NULL;
return false;
}
}

View file

@ -64,7 +64,13 @@ class CG3Protocol : public CProtocol
{
public:
// constructor
CG3Protocol() : m_GwAddress(0u), m_Modules("*"), m_LastModTime(0) {};
CG3Protocol() :
m_GwAddress(0u),
m_Modules("*"),
m_LastModTime(0),
m_pPresenceThread(nullptr),
m_pConfigThread(nullptr),
m_pIcmpThread(nullptr) {}
// destructor
virtual ~CG3Protocol() {};