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

C++: Image's m_logBuffers wrt Move in Subscription::add/remove Image #472

Closed
goglusid opened this issue Feb 26, 2018 · 4 comments
Closed

Comments

@goglusid
Copy link

goglusid commented Feb 26, 2018

I would like to have your opinion on the following. Is it an issue?

Note: I haven't tried to make the following situation happens. At this point, I just suspect this is an issue.

Following is a series of steps leading to the suspected issue:

  1. Application Thread calls:
    inline int pollEndOfStreams(F&& endOfStreamHandler)
    {
      const ImageList * imageList = std::atomic_load_explicit(&m_imageList, std::memory_order_acquire);

Application Thread is somehow interrupted...

  1. Conductor Thread calls:
    Subscription::removeImage/addImage

Because it executes the following code: newArray[j++] = std::move(oldArray[i]);
which calls: m_logBuffers = std::move(image.m_logBuffers);

imageList now contains at least one image where image.m_logBuffers is nullptr.

  1. Application Thread resumes its execution of pollEndOfStreams
      const std::size_t length = imageList->m_length;
      Image *images = imageList->images();
      int numEndOfStreams = 0;

      for (std::size_t i = 0; i < length; i++)
      {
        if (images[i].isEndOfStream()) // **<<< This would crash because m_logBuffers is nullptr**
        {
          numEndOfStreams++;
          endOfStreamHandler(images[i]);
        }
      }

      return numEndOfStreams;
    }
@tmontgomery
Copy link
Contributor

I think you are correct. Would probably be better to use copy semantics instead for add/remove.

@mjpt777
Copy link
Contributor

mjpt777 commented Feb 26, 2018

The same issue applies to the poll methods and other client iteration methods.

@tmontgomery
Copy link
Contributor

Move semantics in now. Feel free to examine it. Feedback always welcome.

@goglusid
Copy link
Author

As usual you are very fast to respond! The changes are fine with me and do resolve the issue I found. Thank you very much!

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

No branches or pull requests

3 participants