Fix possible use of invalid iterator on module unload

When a module quits a user or destroys a channel in OnCleanup() the object is no longer in the container being iterated by the time OnCleanup() returns