util: fix heap-use-after-free in ndn::dns::Resolver

Change-Id: I063edba1b895da36ed4a17a0558e5df820b785a7
Refs: #2653
diff --git a/src/util/dns.cpp b/src/util/dns.cpp
index 0aebc3a..0adfbd2 100644
--- a/src/util/dns.cpp
+++ b/src/util/dns.cpp
@@ -70,6 +70,8 @@
                   iterator it, const shared_ptr<Resolver>& self)
   {
     m_scheduler.cancelEvent(m_resolveTimeout);
+    // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
+    m_resolver.get_io_service().post(bind([] (const shared_ptr<Resolver>&) {}, self));
 
     if (error) {
       if (error == boost::asio::error::operation_aborted)
@@ -95,6 +97,8 @@
   onResolveTimeout(const shared_ptr<Resolver>& self)
   {
     m_resolver.cancel();
+    // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
+    m_resolver.get_io_service().post(bind([] (const shared_ptr<Resolver>&) {}, self));
 
     if (m_onError)
       m_onError("Hostname resolution timed out");