From 911f684e4d8f9932d695cf7bcd571d65a843da17 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 6 Jan 2019 18:17:12 -0800 Subject: [PATCH] DNSLookup: copy hostname and port instead of accessing member --- ixwebsocket/IXDNSLookup.cpp | 6 +++--- ixwebsocket/IXDNSLookup.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ixwebsocket/IXDNSLookup.cpp b/ixwebsocket/IXDNSLookup.cpp index 4e0cd55a..65b5208d 100644 --- a/ixwebsocket/IXDNSLookup.cpp +++ b/ixwebsocket/IXDNSLookup.cpp @@ -105,7 +105,7 @@ namespace ix // Good resource on thread forced termination // https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread // - _thread = std::thread(&DNSLookup::run, this); + _thread = std::thread(&DNSLookup::run, this, _hostname, _port); _thread.detach(); std::unique_lock lock(_conditionVariableMutex); @@ -138,11 +138,11 @@ namespace ix return _res; } - void DNSLookup::run() + void DNSLookup::run(const std::string& hostname, int port) // thread runner { uint64_t id = _id; std::string errMsg; - _res = getAddrInfo(_hostname, _port, errMsg); + _res = getAddrInfo(hostname, port, errMsg); // if this isn't an active job, and the control thread is gone // there is not thing to do, and we don't want to touch the defunct diff --git a/ixwebsocket/IXDNSLookup.h b/ixwebsocket/IXDNSLookup.h index 3ca87c38..dac3d52f 100644 --- a/ixwebsocket/IXDNSLookup.h +++ b/ixwebsocket/IXDNSLookup.h @@ -43,7 +43,7 @@ namespace ix int port, std::string& errMsg); - void run(); // thread runner + void run(const std::string& hostname, int port); // thread runner std::string _hostname; int _port;