Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/statsd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ StatsdClient::StatsdClient(const string& host, int port, const string& ns)
config(host, port, ns);
srandom(time(NULL));
}

StatsdClient::StatsdClient(const StatsdClient &original)
{
// Must create our own storage for ClientData object; don't share original's
d = new _StatsdClientData;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsafe. You should not be managing raw pointers in your class.
If you use std::unique_ptr it will solve this problem.
As it stands this class is broken because it does not implement the rule of three/five (ie there is no assignment operator). So you still have potential malloc errors (though I hope there are no mallocs in your code)

*d = *original.d;

// Don't share original's socket, either.
d->init = false;
d->sock = -1;
}

StatsdClient::~StatsdClient()
{
Expand Down
1 change: 1 addition & 0 deletions src/statsd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct _StatsdClientData;
class StatsdClient {
public:
StatsdClient(const std::string& host="127.0.0.1", int port=8125, const std::string& ns = "");
StatsdClient(const StatsdClient &original);
~StatsdClient();

public:
Expand Down