mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-24 12:39:28 +00:00
Merge pull request #2213 from SChernykh/dev
Fixed use-after-free bug when exiting
This commit is contained in:
commit
89f2fa6818
2 changed files with 10 additions and 6 deletions
|
@ -29,7 +29,11 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
Storage<DnsUvBackend> DnsUvBackend::m_storage;
|
||||
Storage<DnsUvBackend>& DnsUvBackend::getStorage()
|
||||
{
|
||||
static Storage<DnsUvBackend>* storage = new Storage<DnsUvBackend>();
|
||||
return *storage;
|
||||
}
|
||||
|
||||
static addrinfo hints{};
|
||||
|
||||
|
@ -45,13 +49,13 @@ xmrig::DnsUvBackend::DnsUvBackend()
|
|||
hints.ai_protocol = IPPROTO_TCP;
|
||||
}
|
||||
|
||||
m_key = m_storage.add(this);
|
||||
m_key = getStorage().add(this);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -121,7 +125,7 @@ void xmrig::DnsUvBackend::onResolved(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) {
|
||||
backend->onResolved(status, res);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
uint64_t m_ts = 0;
|
||||
uintptr_t m_key;
|
||||
|
||||
static Storage<DnsUvBackend> m_storage;
|
||||
static Storage<DnsUvBackend>& getStorage();
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue