gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24718 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r24718 - gnunet/src/gns
Date: Mon, 5 Nov 2012 13:17:23 +0100

Author: wachs
Date: 2012-11-05 13:17:23 +0100 (Mon, 05 Nov 2012)
New Revision: 24718

Modified:
   gnunet/src/gns/gnunet-service-gns_resolver.c
Log:
fix memory leak

Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c        2012-11-05 12:15:19 UTC 
(rev 24717)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c        2012-11-05 12:17:23 UTC 
(rev 24718)
@@ -658,34 +658,7 @@
   return GNUNET_OK;
 }
 
-
 /**
- * Cleanup ns tasks
- *
- * @param cls closure to iterator
- * @param node heap nodes
- * @param element the namestorebgtask
- * @param cost heap cost
- * @return always GNUNET_YES
- */
-static int
-cleanup_pending_ns_tasks (void* cls,
-                          struct GNUNET_CONTAINER_HeapNode *node,
-                          void *element,
-                          GNUNET_CONTAINER_HeapCostType cost)
-{
-  struct NamestoreBGTask *nbg = element;
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP: Terminating ns task\n");
-  GNUNET_NAMESTORE_cancel (nbg->qe);
-
-  GNUNET_CONTAINER_heap_remove_node (node);
-  return GNUNET_YES;
-}
-
-
-/**
  * finish lookup
  *
  * @param rh resolver handle
@@ -701,38 +674,6 @@
 
 
 /**
- * Cleanup background lookups FIXME get rid of this?? YES this doesn't do
- * anything! => find in code and remove all references to the heap
- *
- * @param cls closure to iterator
- * @param node heap nodes
- * @param element the resolver handle
- * @param cost heap cost
- * @return always GNUNET_YES
- */
-static int
-cleanup_pending_background_queries (void* cls,
-                                    struct GNUNET_CONTAINER_HeapNode *node,
-                                    void *element,
-                                    GNUNET_CONTAINER_HeapCostType cost)
-{
-  struct ResolverHandle *rh = element;
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP-%llu: Terminating background lookup\n",
-             rh->id);
-  GNUNET_CONTAINER_heap_remove_node (node);
-  if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
-  {
-    GNUNET_CONTAINER_heap_iterate (ns_task_heap,
-                                  &cleanup_pending_ns_tasks,
-                                  NULL);    
-  }
-  return GNUNET_YES;
-}
-
-
-/**
  * Helper function to free resolver handle
  *
  * @param rh the handle to free
@@ -772,6 +713,8 @@
     GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
   if (NULL != rh->rd.data)
     GNUNET_free ((void*)(rh->rd.data));
+  if (NULL != rh->dht_heap_node)
+    GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
   GNUNET_free (rh);
 }
 
@@ -804,8 +747,9 @@
 void
 gns_resolver_cleanup ()
 {
-  unsigned int s;
   struct GetPseuAuthorityHandle *tmp;
+  struct ResolverHandle *rh;
+  struct NamestoreBGTask *nbg;
 
   while (NULL != (tmp = gph_head))
   {
@@ -840,21 +784,21 @@
     finish_get_auth (nah_head, nah_head->proc_cls);
   }
 
-  s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP: %u pending background queries to terminate\n", 
-             s);
-  if (0 != s)
-    GNUNET_CONTAINER_heap_iterate (dht_lookup_heap,
-                                   &cleanup_pending_background_queries,
-                                   NULL);
-  else if (0 != GNUNET_CONTAINER_heap_get_size (ns_task_heap))
+  while (NULL != (rh = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap)))
   {
-    GNUNET_CONTAINER_heap_iterate (ns_task_heap,
-                                   &cleanup_pending_ns_tasks,
-                                   NULL);
+      GNUNET_free (rh);
   }
-  // FIXME: what about freeing the heaps themselves?
+  GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
+  dht_lookup_heap = NULL;
+
+  while (NULL != (nbg = GNUNET_CONTAINER_heap_remove_root(ns_task_heap)))
+  {
+      GNUNET_NAMESTORE_cancel (nbg->qe);
+      GNUNET_free (nbg);
+  }
+  GNUNET_CONTAINER_heap_destroy (ns_task_heap);
+  ns_task_heap = NULL;
+
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]