Fixed DnsUvBackend storage cleanup.

This commit is contained in:
XMRig 2023-02-09 21:45:50 +07:00
parent 81e87a6931
commit 667f636c62
No known key found for this signature in database
GPG key ID: 446A53638BE94409
2 changed files with 24 additions and 14 deletions

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,18 +28,19 @@
namespace xmrig {
static Storage<DnsUvBackend>* storage = nullptr;
Storage<DnsUvBackend>& DnsUvBackend::getStorage()
static Storage<DnsUvBackend> *storage = nullptr;
Storage<DnsUvBackend> &DnsUvBackend::getStorage()
{
if (storage == nullptr) storage = new Storage<DnsUvBackend>();
if (storage == nullptr) {
storage = new Storage<DnsUvBackend>();
}
return *storage;
}
void DnsUvBackend::releaseStorage()
{
delete storage;
}
static addrinfo hints{};
@ -61,8 +62,14 @@ xmrig::DnsUvBackend::DnsUvBackend()
xmrig::DnsUvBackend::~DnsUvBackend()
{
getStorage().release(m_key);
releaseStorage();
assert(storage);
storage->release(m_key);
if (storage->isEmpty()) {
delete storage;
storage = nullptr;
}
}

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,7 +42,7 @@ public:
}
inline void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
inline TYPE *ptr(uintptr_t id) { return reinterpret_cast<TYPE *>(id); }
inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
@ -56,6 +56,9 @@ public:
return m_data.at(id);
}
inline bool isEmpty() const { return m_data.empty(); }
inline size_t size() const { return m_data.size(); }
inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); }
inline void remove(uintptr_t id) { delete release(id); }