From 87eb62b4eb01c8bfcf3d2194d3b60fe82fc5c09a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 22 Aug 2018 21:52:56 +0200 Subject: [PATCH] Fixed new/free mismatch and uninit memory usage --- src/common/Platform_mac.cpp | 2 +- src/common/Platform_unix.cpp | 2 +- src/common/Platform_win.cpp | 2 +- src/common/net/Pool.cpp | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index b8181cc4..7a2849b0 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -42,7 +42,7 @@ static inline char *createUserAgent() { const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); # ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 97b32ee8..15be0f5f 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -56,7 +56,7 @@ static inline char *createUserAgent() { const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); # if defined(__x86_64__) diff --git a/src/common/Platform_win.cpp b/src/common/Platform_win.cpp index 47f41867..7026fd17 100644 --- a/src/common/Platform_win.cpp +++ b/src/common/Platform_win.cpp @@ -60,7 +60,7 @@ static inline char *createUserAgent() const auto osver = winOsVersion(); const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); # if defined(__x86_64__) || defined(_M_AMD64) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index bfe42b51..aa9c943e 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -97,7 +97,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo const size_t size = m_host.size() + 8; assert(size > 8); - char *url = new char[size](); + char *url = static_cast(malloc(size)); snprintf(url, size - 1, "%s:%d", m_host.data(), m_port); m_url = url; @@ -171,8 +171,9 @@ bool Pool::parse(const char *url) } const size_t size = port++ - base + 1; - char *host = new char[size](); + char *host = static_cast(malloc(size)); memcpy(host, base, size - 1); + host[size - 1] = 0; m_host = host; m_port = static_cast(strtol(port, nullptr, 10)); @@ -188,7 +189,7 @@ bool Pool::setUserpass(const char *userpass) return false; } - char *user = new char[p - userpass + 1](); + char *user = static_cast(malloc(p - userpass + 1)); strncpy(user, userpass, p - userpass); m_user = user; @@ -279,7 +280,7 @@ bool Pool::parseIPv6(const char *addr) } const size_t size = end - addr; - char *host = new char[size](); + char *host = static_cast(malloc(size)); memcpy(host, addr + 1, size - 1); m_host = host;