Monitor: avoid null pointer dereference when copying instances
When the copy constructor was added to allow passing a monitor by value into a lambda the implementation did not account for the possibility of the watchable having already been destroyed. Also provide the companion copy assignment to complete the triad.
This commit is contained in:
parent
adf4fb3bc1
commit
94bff62986
|
|
@ -64,7 +64,25 @@ public:
|
|||
Monitor(const Monitor &monitor) : _watchable(monitor._watchable)
|
||||
{
|
||||
// register with the watchable
|
||||
_watchable->add(this);
|
||||
if (_watchable) _watchable->add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @param monitor
|
||||
*/
|
||||
Monitor& operator= (const Monitor &monitor)
|
||||
{
|
||||
// remove from watchable
|
||||
if (_watchable) _watchable->remove(this);
|
||||
|
||||
// replace watchable
|
||||
_watchable = monitor._watchable;
|
||||
|
||||
// register with the watchable
|
||||
if (_watchable) _watchable->add(this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue