diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-05 12:17:23 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-05 12:17:23 +0000 |
commit | 2158963e722a42fd436407611cc817c04c2fd5e6 (patch) | |
tree | d4c2c7c048233c95ba1bca72619af399bc143fd3 /src/gns | |
parent | 747234f53f8c184b2a347e0f064c39161a5a09b9 (diff) | |
download | gnunet-2158963e722a42fd436407611cc817c04c2fd5e6.tar.gz gnunet-2158963e722a42fd436407611cc817c04c2fd5e6.zip |
fix memory leak
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 90 |
1 files changed, 17 insertions, 73 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 76eb46df0..058d0c971 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -658,33 +658,6 @@ gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, | |||
658 | return GNUNET_OK; | 658 | return GNUNET_OK; |
659 | } | 659 | } |
660 | 660 | ||
661 | |||
662 | /** | ||
663 | * Cleanup ns tasks | ||
664 | * | ||
665 | * @param cls closure to iterator | ||
666 | * @param node heap nodes | ||
667 | * @param element the namestorebgtask | ||
668 | * @param cost heap cost | ||
669 | * @return always GNUNET_YES | ||
670 | */ | ||
671 | static int | ||
672 | cleanup_pending_ns_tasks (void* cls, | ||
673 | struct GNUNET_CONTAINER_HeapNode *node, | ||
674 | void *element, | ||
675 | GNUNET_CONTAINER_HeapCostType cost) | ||
676 | { | ||
677 | struct NamestoreBGTask *nbg = element; | ||
678 | |||
679 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
680 | "GNS_CLEANUP: Terminating ns task\n"); | ||
681 | GNUNET_NAMESTORE_cancel (nbg->qe); | ||
682 | |||
683 | GNUNET_CONTAINER_heap_remove_node (node); | ||
684 | return GNUNET_YES; | ||
685 | } | ||
686 | |||
687 | |||
688 | /** | 661 | /** |
689 | * finish lookup | 662 | * finish lookup |
690 | * | 663 | * |
@@ -701,38 +674,6 @@ finish_lookup (struct ResolverHandle *rh, | |||
701 | 674 | ||
702 | 675 | ||
703 | /** | 676 | /** |
704 | * Cleanup background lookups FIXME get rid of this?? YES this doesn't do | ||
705 | * anything! => find in code and remove all references to the heap | ||
706 | * | ||
707 | * @param cls closure to iterator | ||
708 | * @param node heap nodes | ||
709 | * @param element the resolver handle | ||
710 | * @param cost heap cost | ||
711 | * @return always GNUNET_YES | ||
712 | */ | ||
713 | static int | ||
714 | cleanup_pending_background_queries (void* cls, | ||
715 | struct GNUNET_CONTAINER_HeapNode *node, | ||
716 | void *element, | ||
717 | GNUNET_CONTAINER_HeapCostType cost) | ||
718 | { | ||
719 | struct ResolverHandle *rh = element; | ||
720 | |||
721 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
722 | "GNS_CLEANUP-%llu: Terminating background lookup\n", | ||
723 | rh->id); | ||
724 | GNUNET_CONTAINER_heap_remove_node (node); | ||
725 | if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap)) | ||
726 | { | ||
727 | GNUNET_CONTAINER_heap_iterate (ns_task_heap, | ||
728 | &cleanup_pending_ns_tasks, | ||
729 | NULL); | ||
730 | } | ||
731 | return GNUNET_YES; | ||
732 | } | ||
733 | |||
734 | |||
735 | /** | ||
736 | * Helper function to free resolver handle | 677 | * Helper function to free resolver handle |
737 | * | 678 | * |
738 | * @param rh the handle to free | 679 | * @param rh the handle to free |
@@ -772,6 +713,8 @@ free_resolver_handle (struct ResolverHandle* rh) | |||
772 | GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle); | 713 | GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle); |
773 | if (NULL != rh->rd.data) | 714 | if (NULL != rh->rd.data) |
774 | GNUNET_free ((void*)(rh->rd.data)); | 715 | GNUNET_free ((void*)(rh->rd.data)); |
716 | if (NULL != rh->dht_heap_node) | ||
717 | GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node); | ||
775 | GNUNET_free (rh); | 718 | GNUNET_free (rh); |
776 | } | 719 | } |
777 | 720 | ||
@@ -804,8 +747,9 @@ finish_get_auth (struct ResolverHandle *rh, | |||
804 | void | 747 | void |
805 | gns_resolver_cleanup () | 748 | gns_resolver_cleanup () |
806 | { | 749 | { |
807 | unsigned int s; | ||
808 | struct GetPseuAuthorityHandle *tmp; | 750 | struct GetPseuAuthorityHandle *tmp; |
751 | struct ResolverHandle *rh; | ||
752 | struct NamestoreBGTask *nbg; | ||
809 | 753 | ||
810 | while (NULL != (tmp = gph_head)) | 754 | while (NULL != (tmp = gph_head)) |
811 | { | 755 | { |
@@ -840,21 +784,21 @@ gns_resolver_cleanup () | |||
840 | finish_get_auth (nah_head, nah_head->proc_cls); | 784 | finish_get_auth (nah_head, nah_head->proc_cls); |
841 | } | 785 | } |
842 | 786 | ||
843 | s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap); | 787 | while (NULL != (rh = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap))) |
844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | { |
845 | "GNS_CLEANUP: %u pending background queries to terminate\n", | 789 | GNUNET_free (rh); |
846 | s); | 790 | } |
847 | if (0 != s) | 791 | GNUNET_CONTAINER_heap_destroy (dht_lookup_heap); |
848 | GNUNET_CONTAINER_heap_iterate (dht_lookup_heap, | 792 | dht_lookup_heap = NULL; |
849 | &cleanup_pending_background_queries, | 793 | |
850 | NULL); | 794 | while (NULL != (nbg = GNUNET_CONTAINER_heap_remove_root(ns_task_heap))) |
851 | else if (0 != GNUNET_CONTAINER_heap_get_size (ns_task_heap)) | ||
852 | { | 795 | { |
853 | GNUNET_CONTAINER_heap_iterate (ns_task_heap, | 796 | GNUNET_NAMESTORE_cancel (nbg->qe); |
854 | &cleanup_pending_ns_tasks, | 797 | GNUNET_free (nbg); |
855 | NULL); | ||
856 | } | 798 | } |
857 | // FIXME: what about freeing the heaps themselves? | 799 | GNUNET_CONTAINER_heap_destroy (ns_task_heap); |
800 | ns_task_heap = NULL; | ||
801 | |||
858 | } | 802 | } |
859 | 803 | ||
860 | 804 | ||