shill: Unbind DHCPConfig from it's PID when dhcpcd is killed.

This allows the destruction of the DHCPConfig instance. The patch also
refactors and cleans up a bit resetting of client state in DHCPConfig.

BUG=chromium-os:37652
TEST=unit tests; tested on device by connecting to different APs, then
'stop shill' and inspecting logs for any stale DHCPConfig object
destructions; checked connectivity.

Change-Id: I991011191b553daa970b9225b85696f20add9dea
Reviewed-on: https://gerrit.chromium.org/gerrit/42532
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: Darin Petkov <petkov@chromium.org>
diff --git a/dhcp_config_unittest.cc b/dhcp_config_unittest.cc
index 559eb1a..5bf2223 100644
--- a/dhcp_config_unittest.cc
+++ b/dhcp_config_unittest.cc
@@ -553,15 +553,17 @@
 }
 
 TEST_F(DHCPConfigTest, Stop) {
-  // Ensure no crashes.
   const int kPID = 1 << 17;  // Ensure unknown positive PID.
   ScopedMockLog log;
   EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber());
   EXPECT_CALL(log, Log(_, _, ContainsRegex(
-      base::StringPrintf("Terminating.+%s", __func__))));
+      base::StringPrintf("Stopping.+%s", __func__))));
   config_->pid_ = kPID;
+  DHCPProvider::GetInstance()->BindPID(kPID, config_);
   config_->Stop(__func__);
   EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled());
+  EXPECT_FALSE(DHCPProvider::GetInstance()->GetConfig(kPID));
+  EXPECT_FALSE(config_->pid_);
 }
 
 TEST_F(DHCPConfigTest, StopDuringRequestIP) {