Fixed new/free mismatch and uninit memory usage

This commit is contained in:
MoneroOcean 2018-08-22 21:52:56 +02:00
parent 1a819c6189
commit 87eb62b4eb
4 changed files with 8 additions and 7 deletions

View file

@ -42,7 +42,7 @@ static inline char *createUserAgent()
{
const size_t max = 160;
char *buf = new char[max];
char *buf = static_cast<char *>(malloc(max));
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();

View file

@ -56,7 +56,7 @@ static inline char *createUserAgent()
{
const size_t max = 160;
char *buf = new char[max];
char *buf = static_cast<char *>(malloc(max));
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
# if defined(__x86_64__)

View file

@ -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<char *>(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)

View file

@ -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<char *>(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<char *>(malloc(size));
memcpy(host, base, size - 1);
host[size - 1] = 0;
m_host = host;
m_port = static_cast<uint16_t>(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<char *>(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<char *>(malloc(size));
memcpy(host, addr + 1, size - 1);
m_host = host;