fix memory leak in ccnx-tunnel
diff --git a/src/ccnx-closure.cpp b/src/ccnx-closure.cpp
index a4c378c..528c721 100644
--- a/src/ccnx-closure.cpp
+++ b/src/ccnx-closure.cpp
@@ -44,4 +44,11 @@
   }
 }
 
+Closure *
+Closure::dup() const
+{
+  Closure *closure = new Closure(*this);
+  return closure;
+}
+
 } // Ccnx
diff --git a/src/ccnx-tunnel.cpp b/src/ccnx-tunnel.cpp
index 5e4d322..6a7dd29 100644
--- a/src/ccnx-tunnel.cpp
+++ b/src/ccnx-tunnel.cpp
@@ -8,7 +8,7 @@
                           : CcnxWrapper()
                           , m_localPrefix("/")
 {
-  //refreshLocalPrefix();
+  refreshLocalPrefix();
 }
 
 CcnxTunnel::~CcnxTunnel()
@@ -28,11 +28,12 @@
 }
 
 int
-CcnxTunnel::sendInterest (const Name &interest, Closure *closure, const Selectors &selectors)
+CcnxTunnel::sendInterest (const Name &interest, const Closure *closure, const Selectors &selectors)
 {
   Name tunneledInterest = queryRoutableName(interest);
   Closure *cp = new TunnelClosure(closure, this, interest);
   CcnxWrapper::sendInterest(tunneledInterest, cp, selectors);
+  delete cp;
 }
 
 void
@@ -55,7 +56,6 @@
 CcnxTunnel::publishContentObject(const Name &name, const Bytes &contentObject, int freshness)
 {
   Name tunneledName = m_localPrefix + name;
-  cout << "Outer name " << tunneledName;
   Bytes tunneledCo = createContentObject(tunneledName, head(contentObject), contentObject.size(), freshness);
   return putToCcnd(tunneledCo);
 }
@@ -129,6 +129,13 @@
 {
 }
 
+Closure *
+TunnelClosure::dup() const
+{
+  Closure *closure = new TunnelClosure(m_retry, *m_dataCallback, m_tunnel, m_originalInterest, *m_timeoutCallback);
+  return closure;
+}
+
 void
 TunnelClosure::runDataCallback(const Name &name, const Bytes &content)
 {
diff --git a/src/ccnx-wrapper.cpp b/src/ccnx-wrapper.cpp
index 981fdd4..0f4a8d5 100644
--- a/src/ccnx-wrapper.cpp
+++ b/src/ccnx-wrapper.cpp
@@ -257,6 +257,8 @@
   switch (kind)
     {
     case CCN_UPCALL_FINAL:  // effecitve in unit tests
+      delete cp;
+      cp = NULL;
       delete selfp;
       return CCN_UPCALL_RESULT_OK;
 
@@ -303,7 +305,7 @@
   return CCN_UPCALL_RESULT_OK;
 }
 
-int CcnxWrapper::sendInterest (const Name &interest, Closure *closure, const Selectors &selectors)
+int CcnxWrapper::sendInterest (const Name &interest, const Closure *closure, const Selectors &selectors)
 {
   UniqueRecLock(m_mutex);
   if (!m_running || !m_connected)
@@ -313,7 +315,8 @@
   ccn_charbuf *pname = namePtr->getBuf();
   ccn_closure *dataClosure = new ccn_closure;
 
-  dataClosure->data = (void *)closure;
+  Closure *myClosure = closure->dup();
+  dataClosure->data = (void *)myClosure;
 
   dataClosure->p = &incomingData;