Merge pull request #2213 from SChernykh/dev

Fixed use-after-free bug when exiting
This commit is contained in:
xmrig 2021-03-28 09:55:50 +07:00 committed by GitHub
commit 89f2fa6818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -29,7 +29,11 @@
namespace xmrig { namespace xmrig {
Storage<DnsUvBackend> DnsUvBackend::m_storage; Storage<DnsUvBackend>& DnsUvBackend::getStorage()
{
static Storage<DnsUvBackend>* storage = new Storage<DnsUvBackend>();
return *storage;
}
static addrinfo hints{}; static addrinfo hints{};
@ -45,13 +49,13 @@ xmrig::DnsUvBackend::DnsUvBackend()
hints.ai_protocol = IPPROTO_TCP; hints.ai_protocol = IPPROTO_TCP;
} }
m_key = m_storage.add(this); m_key = getStorage().add(this);
} }
xmrig::DnsUvBackend::~DnsUvBackend() xmrig::DnsUvBackend::~DnsUvBackend()
{ {
m_storage.release(m_key); getStorage().release(m_key);
} }
@ -76,7 +80,7 @@ std::shared_ptr<xmrig::DnsRequest> xmrig::DnsUvBackend::resolve(const String &ho
bool xmrig::DnsUvBackend::resolve(const String &host) bool xmrig::DnsUvBackend::resolve(const String &host)
{ {
m_req = std::make_shared<uv_getaddrinfo_t>(); m_req = std::make_shared<uv_getaddrinfo_t>();
m_req->data = m_storage.ptr(m_key); m_req->data = getStorage().ptr(m_key);
m_status = uv_getaddrinfo(uv_default_loop(), m_req.get(), DnsUvBackend::onResolved, host.data(), nullptr, &hints); m_status = uv_getaddrinfo(uv_default_loop(), m_req.get(), DnsUvBackend::onResolved, host.data(), nullptr, &hints);
@ -121,7 +125,7 @@ void xmrig::DnsUvBackend::onResolved(int status, addrinfo *res)
void xmrig::DnsUvBackend::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res) void xmrig::DnsUvBackend::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
{ {
auto backend = m_storage.get(req->data); auto backend = getStorage().get(req->data);
if (backend) { if (backend) {
backend->onResolved(status, res); backend->onResolved(status, res);
} }

View file

@ -61,7 +61,7 @@ private:
uint64_t m_ts = 0; uint64_t m_ts = 0;
uintptr_t m_key; uintptr_t m_key;
static Storage<DnsUvBackend> m_storage; static Storage<DnsUvBackend>& getStorage();
}; };