Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement copy constructor to prevent malloc errors #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jamesmulcahy
Copy link

Fixes #1

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of default copy constructor causes SEGVs
2 participants