Skip to content

Commit

Permalink
Monitor: avoid null pointer dereference when copying instances
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pabigot committed Jun 24, 2018
1 parent adf4fb3 commit 94bff62
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion include/amqpcpp/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,25 @@ class Monitor
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;
}

/**
Expand Down

0 comments on commit 94bff62

Please sign in to comment.