Fixed memory leak.

This commit is contained in:
XMRig
2019-11-28 07:25:10 +07:00
parent f65b647791
commit fc35957d83
3 changed files with 28 additions and 9 deletions

View File

@@ -31,10 +31,12 @@ static inline uint8_t hf_hex2bin(uint8_t c, bool &err)
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'f') {
if (c >= 'a' && c <= 'f') {
return c - 'a' + 0xA;
}
else if (c >= 'A' && c <= 'F') {
if (c >= 'A' && c <= 'F') {
return c - 'A' + 0xA;
}
@@ -77,7 +79,9 @@ xmrig::Buffer::Buffer(const char *data, size_t size)
xmrig::Buffer::Buffer(size_t size) :
m_size(size)
{
m_data = new char[size]();
if (size > 0) {
m_data = new char[size]();
}
}
@@ -105,6 +109,10 @@ void xmrig::Buffer::from(const char *data, size_t size)
xmrig::Buffer xmrig::Buffer::allocUnsafe(size_t size)
{
if (size == 0) {
return {};
}
Buffer buf;
buf.m_size = size;
buf.m_data = new char[size];
@@ -169,6 +177,13 @@ xmrig::String xmrig::Buffer::toHex() const
void xmrig::Buffer::copy(const char *data, size_t size)
{
if (size == 0) {
m_data = nullptr;
m_size = 0;
return;
}
m_data = new char[size];
m_size = size;

View File

@@ -62,7 +62,6 @@ namespace xmrig {
xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port) :
m_ip(),
m_routeId(-1),
m_id(++nextId),
m_loginId(0),
@@ -102,7 +101,12 @@ xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port) :
xmrig::Miner::~Miner()
{
Handle::close(m_socket);
if (uv_is_closing(reinterpret_cast<uv_handle_t *>(m_socket))) {
delete m_socket;
}
else {
uv_close(reinterpret_cast<uv_handle_t *>(m_socket), [](uv_handle_t *handle) { delete handle; });
}
# ifdef XMRIG_FEATURE_TLS
delete m_tls;

View File

@@ -123,9 +123,9 @@ private:
static inline Miner *getMiner(void *data) { return m_storage.get(data); }
char m_buf[4096];
char m_ip[46];
char m_rpcId[37];
char m_buf[4096]{};
char m_ip[46]{};
char m_rpcId[37]{};
int32_t m_routeId;
int64_t m_id;
int64_t m_loginId;
@@ -147,7 +147,7 @@ private:
uint64_t m_tx;
uint8_t m_fixedByte;
uintptr_t m_key;
uv_buf_t m_recvBuf;
uv_buf_t m_recvBuf{};
uv_tcp_t *m_socket;
static char m_sendBuf[2048];