eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.65k stars 385 forks source link

Fix resource leak caused by move ctor/assignment #542

Closed elfenpiff closed 3 years ago

elfenpiff commented 3 years ago

Required information

All versions

Observed result or behaviour: The classes:

are not cleaning up the resources while performing move. This could lead to a resource leak when for instance the following pseudo code is executed.

SharedMemory mySharedMemory; // create a shared memory file A
SharedMemory anotherSharedMemory; // create a shared memory file B

mySharedMemory = std::move(anotherSharedMemory); // mySharedMemory takes ownership of B without releasing A

// at this point the shared memory file A is leaked

Classes with correct move resource handling:

Handle undefined state:

creation pattern:

Fix incorrect move CTor/assigned in all classes derived from DesignPattern::Creation According to: https://isocpp.org/wiki/faq/assignment-operators every move ctor/assignment operator has to be implemented like

Derived& Derived::operator= (Derived&& d)
{
  // self-assignment is not allowed in move assignment
  Base::operator= (std::move(d));
  // Do the rest of your assignment operator here...
  return *this;
}

Fix sighandler

Details

elfenpiff commented 3 years ago

@sschnitzer Thank you for finding this!