[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9865 - GNUnet/src/util/containers
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9865 - GNUnet/src/util/containers |
Date: |
Tue, 22 Dec 2009 22:17:25 +0100 |
Author: nevans
Date: 2009-12-22 22:17:25 +0100 (Tue, 22 Dec 2009)
New Revision: 9865
Modified:
GNUnet/src/util/containers/heap.c
GNUnet/src/util/containers/heaptest.c
Log:
heap leak fix
Modified: GNUnet/src/util/containers/heap.c
===================================================================
--- GNUnet/src/util/containers/heap.c 2009-12-22 19:20:57 UTC (rev 9864)
+++ GNUnet/src/util/containers/heap.c 2009-12-22 21:17:25 UTC (rev 9865)
@@ -112,7 +112,8 @@
return heap;
}
-void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *root)
+void *
+GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *root)
{
if ((root == NULL) || (root->root == NULL))
return NULL;
@@ -133,21 +134,21 @@
struct GNUNET_CONTAINER_heap_node *ret;
ret = NULL;
- if ((node != NULL) && (node->element == element))
- {
- ret = node;
- }
-
- if ((ret == NULL) && (node != NULL) && (node->left_child != NULL))
- {
- ret = find_element (node->left_child, element);
- }
-
- if ((ret == NULL) && (node != NULL) && (node->right_child != NULL))
- {
- ret = find_element (node->right_child, element);
- }
-
+ if ((node != NULL) && (node->element == element))
+ {
+ ret = node;
+ }
+
+ if ((ret == NULL) && (node != NULL) && (node->left_child != NULL))
+ {
+ ret = find_element (node->left_child, element);
+ }
+
+ if ((ret == NULL) && (node != NULL) && (node->right_child != NULL))
+ {
+ ret = find_element (node->right_child, element);
+ }
+
return ret;
}
@@ -354,7 +355,7 @@
if (last == del_node)
{
- GNUNET_free(last);
+ GNUNET_free (last);
return ret;
}
@@ -425,6 +426,7 @@
if ((root_node == last) && (root->size == 1)) /* We are removing the last
node in the heap! */
{
+ GNUNET_free (root->root);
root->root = NULL;
root->traversal_pos = NULL;
root->size = 0;
@@ -499,9 +501,11 @@
int ret;
if (node == NULL)
return GNUNET_YES;
- if (GNUNET_YES != (ret =internal_iterator (root, node->left_child, iterator,
cls)))
+ if (GNUNET_YES !=
+ (ret = internal_iterator (root, node->left_child, iterator, cls)))
return ret;
- if (GNUNET_YES != (ret = internal_iterator (root, node->right_child,
iterator, cls)))
+ if (GNUNET_YES !=
+ (ret = internal_iterator (root, node->right_child, iterator, cls)))
return ret;
return iterator (node->element, node->cost, root, cls);
}
Modified: GNUnet/src/util/containers/heaptest.c
===================================================================
--- GNUnet/src/util/containers/heaptest.c 2009-12-22 19:20:57 UTC (rev
9864)
+++ GNUnet/src/util/containers/heaptest.c 2009-12-22 21:17:25 UTC (rev
9865)
@@ -55,7 +55,7 @@
struct GNUNET_dv_neighbor *neighbor5;
struct GNUNET_dv_neighbor *neighbor6;
- myHeap = GNUNET_CONTAINER_heap_create (GNUNET_MAX_HEAP);
+ myHeap = GNUNET_CONTAINER_heap_create (GNUNET_MIN_HEAP);
neighbor1 = malloc (sizeof (struct GNUNET_dv_neighbor));
neighbor2 = malloc (sizeof (struct GNUNET_dv_neighbor));
@@ -64,23 +64,31 @@
neighbor5 = malloc (sizeof (struct GNUNET_dv_neighbor));
neighbor6 = malloc (sizeof (struct GNUNET_dv_neighbor));
- neighbor1->cost = 60;
- neighbor2->cost = 50;
- neighbor3->cost = 70;
- neighbor4->cost = 120;
+ neighbor1->cost = 11;
+ neighbor2->cost = 78;
+ neighbor3->cost = 5;
+ neighbor4->cost = 50;
neighbor5->cost = 100;
neighbor6->cost = 30;
GNUNET_CONTAINER_heap_insert (myHeap, neighbor1, neighbor1->cost);
GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
+ fprintf (stderr, "size is %d\n", GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_insert (myHeap, neighbor2, neighbor2->cost);
+ fprintf (stderr, "size is %d\n", GNUNET_CONTAINER_heap_get_size (myHeap));
+ GNUNET_CONTAINER_heap_remove_node (myHeap, neighbor2);
+ fprintf (stderr, "size is %d\n", GNUNET_CONTAINER_heap_get_size (myHeap));
+
GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
GNUNET_CONTAINER_heap_insert (myHeap, neighbor3, neighbor3->cost);
+ GNUNET_CONTAINER_heap_update_cost (myHeap, neighbor3, 15);
+ fprintf (stderr, "size is %d\n", GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
GNUNET_CONTAINER_heap_insert (myHeap, neighbor4, neighbor4->cost);
+ fprintf (stderr, "size is %d\n", GNUNET_CONTAINER_heap_get_size (myHeap));
GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
GNUNET_CONTAINER_heap_insert (myHeap, neighbor5, neighbor5->cost);
@@ -100,6 +108,13 @@
GNUNET_CONTAINER_heap_destroy (myHeap);
+ GNUNET_free (neighbor1);
+ GNUNET_free (neighbor2);
+ GNUNET_free (neighbor3);
+ GNUNET_free (neighbor4);
+ GNUNET_free (neighbor5);
+ GNUNET_free (neighbor6);
+
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9865 - GNUnet/src/util/containers,
gnunet <=