iceoryx
iceoryx copied to clipboard
Lifetime issue when storing a `popo::Sample`
Required information
Operating system: Any
Compiler version: Any
Observed result or behaviour:
Comes from this comment:
You have a livetime issue here. See this code:
SamplePointer<SampleType>&& acquireSample() { EventPublisher<Topic> publisher; return std::move(publisher.Loan()); } int main() { auto sample = acquireSample(); }
In the end you can construct a lot of examples where the EventPublisher goes out of scope before SamplePointer does and then one has a problem. I think this is another problem with the automotive API where one has to state at least a big red warning that the EventPublisher has to live as least as long as the SamplePointer.
But just so that you are aware how bad this problem is, take a look at this evil bug:
class MyClass { SamplePointer<SampleType> m_sample; EventPublisher<Topic> m_publisher; }
This ordering of member variables is evil, when the MyClass destructor destroys the member it does it in inverse order, first the m_publisher and then the m_sample and one has again undefined behavior. I would bet in a code review no one would have seen this. There are a lot of bugs out there where applications cannot terminate cleanly and cause leaks or segfaults because of this issue.
Expected result or behaviour:
Add a notification in each of the destructors like it is done for WaitSet
and Listener
.
Conditions where it occurred / Performed steps: See above
@mossmaurice this is a duplicate of #560 if I understand this correct