mgmt: Controller cleans up fetchers on destruction

refs: #4775

Change-Id: I795b1ee273d0cca6df23be6c87255fc6d33b3651
diff --git a/src/mgmt/nfd/controller.cpp b/src/mgmt/nfd/controller.cpp
index 1af70b7..05570fd 100644
--- a/src/mgmt/nfd/controller.cpp
+++ b/src/mgmt/nfd/controller.cpp
@@ -22,7 +22,6 @@
 #include "controller.hpp"
 #include "face.hpp"
 #include "security/v2/key-chain.hpp"
-#include "util/segment-fetcher.hpp"
 
 #include <boost/lexical_cast.hpp>
 
@@ -45,6 +44,13 @@
 {
 }
 
+Controller::~Controller()
+{
+  for (const auto& sp : m_fetchers) {
+    sp->stop();
+  }
+}
+
 void
 Controller::startCommand(const shared_ptr<ControlCommand>& command,
                          const ControlParameters& parameters,
@@ -151,6 +157,10 @@
       processDatasetFetchError(onFailure, code, msg);
     });
   }
+
+  auto it = m_fetchers.insert(fetcher).first;
+  fetcher->onComplete.connect([this, it] (ConstBufferPtr) { m_fetchers.erase(it); });
+  fetcher->onError.connect([this, it] (uint32_t, const std::string&) { m_fetchers.erase(it); });
 }
 
 void