shill: stop devices when deregistering them

update Manager::DeregisterDevice, to call Stop before forgetting
about a device. this is needed in particular for WiFi. without
the call to Stop, cyclic references prevent the WiFi object from
being deleted when Manager forgets it.

BUG=chromium-os:16419
TEST=WiFiManager+new unittest

note that shill doesn't actually pass any of the WiFiManager
tests yet. but this patch eliminates one of the situations in
which it might crash.

Change-Id: I067b80745a05e060430a6d403c47b5c6fa186b51
Reviewed-on: http://gerrit.chromium.org/gerrit/6673
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/manager.cc b/manager.cc
index 034f40e..1b8810f 100644
--- a/manager.cc
+++ b/manager.cc
@@ -149,14 +149,17 @@
     to_manage->Start();
 }
 
-void Manager::DeregisterDevice(const DeviceConstRefPtr &to_forget) {
+void Manager::DeregisterDevice(const DeviceRefPtr &to_forget) {
   vector<DeviceRefPtr>::iterator it;
   for (it = devices_.begin(); it != devices_.end(); ++it) {
     if (to_forget.get() == it->get()) {
+      VLOG(2) << "Deregistered device: " << to_forget->UniqueName();
+      to_forget->Stop();
       devices_.erase(it);
       return;
     }
   }
+  VLOG(2) << __func__ << " unknown device: " << to_forget->UniqueName();
 }
 
 void Manager::RegisterService(const ServiceRefPtr &to_manage) {