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

Object assignment operator causes duplicated releasing #200

Closed
feipengsy opened this issue Jul 22, 2021 · 1 comment · Fixed by #201
Closed

Object assignment operator causes duplicated releasing #200

feipengsy opened this issue Jul 22, 2021 · 1 comment · Fixed by #201

Comments

@feipengsy
Copy link

It seems the generated object assignment operator doesn't increase the reference count of the underlying Obj.

For example, this is the generated assignment operator:

Hit& Hit::operator=(const Hit& other) {
  if ( m_obj != nullptr) m_obj->release();
  m_obj = other.m_obj;
  return *this;
}

And some code like this would cause problems:

std::map<int,Hit> HitMap;
for(...) {
    Hit aHit = Hit();
    ...
    HitMap[i] = aHit;
}// Hits in the HitMap becomes invalid after the loop.

Is this by design or unexpected? Maybe add a m_obj->acquire() as well.

@tmadlener
Copy link
Collaborator

Hi @feipengsy,

thanks for reporting this. This is indeed a bug and the assignment operator should acquire to increase the reference count.

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 a pull request may close this issue.

2 participants