Skip to content

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

Closed
@goglusid

Description

@goglusid

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions