Skip to content

Commit

Permalink
Fixed new/free mismatch and uninit memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MoneroOcean committed Aug 22, 2018
1 parent 1a819c6 commit 87eb62b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/Platform_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/common/Platform_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion src/common/Platform_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/common/net/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 87eb62b

Please sign in to comment.