Fix shill unittest bugs - singleton instances must be handled properly across different unittests.

Unittests for shill is a single executable, which run each unittest
one by one, so for each singleton, we must setup up and clear
properly, we must not make any assumption that this singleton is used
only for a particular test.

For instance in config80211_unittest.cc, singleton member
'Config80211::sock_' is assigned a value which invalidates right after
Config80211Test finishes, when later ShillDaemonTest::Start comes to
this non-NULL value, thinking that this is properly initialized and
makes a call on it, the program crashes.

TEST=all shill tests passed after fixing (was crashing)
BUG=None

Change-Id: Ifd17bfca319e4f5d93cb82bdde010d9a5db36dcd
Reviewed-on: https://gerrit.chromium.org/gerrit/39771
Reviewed-by: Wade Guthrie <wdg@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Commit-Ready: Han Shen <shenhan@chromium.org>
Tested-by: Han Shen <shenhan@chromium.org>
diff --git a/config80211_unittest.cc b/config80211_unittest.cc
index d9e93c8..3db52e3 100644
--- a/config80211_unittest.cc
+++ b/config80211_unittest.cc
@@ -360,6 +360,12 @@
 class Config80211Test : public Test {
  public:
   Config80211Test() : config80211_(Config80211::GetInstance()) {}
+  ~Config80211Test() {
+    // Config80211 is a singleton, the sock_ field *MUST* be cleared
+    // before "Config80211Test::socket_" gets invalidated, otherwise
+    // later tests will refer to a corrupted memory.
+    config80211_->sock_ = NULL;
+  }
   void SetupConfig80211Object() {
     EXPECT_NE(config80211_, reinterpret_cast<Config80211 *>(NULL));
     config80211_->sock_ = &socket_;