aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_heap.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-08 13:23:16 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-08 13:23:16 +0000
commita7a976060536ea4f95b8036194e5e5a68567d0ce (patch)
tree4c196f53c5cf25cfa23634d149f8d05fb6ef1a4b /src/util/container_heap.c
parent1c77704470683ebcb42b8dd0b7290018fb6340bf (diff)
downloadgnunet-a7a976060536ea4f95b8036194e5e5a68567d0ce.tar.gz
gnunet-a7a976060536ea4f95b8036194e5e5a68567d0ce.zip
fixing leak
Diffstat (limited to 'src/util/container_heap.c')
-rw-r--r--src/util/container_heap.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 9d252159f..9a2afaebc 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -132,7 +132,6 @@ GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap)
132 while (heap->size > 0) 132 while (heap->size > 0)
133 GNUNET_CONTAINER_heap_remove_root (heap); 133 GNUNET_CONTAINER_heap_remove_root (heap);
134 GNUNET_free (heap); 134 GNUNET_free (heap);
135 return;
136} 135}
137 136
138static struct GNUNET_CONTAINER_heap_node * 137static struct GNUNET_CONTAINER_heap_node *
@@ -393,16 +392,22 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *root)
393 struct GNUNET_CONTAINER_heap_node *root_node; 392 struct GNUNET_CONTAINER_heap_node *root_node;
394 struct GNUNET_CONTAINER_heap_node *last; 393 struct GNUNET_CONTAINER_heap_node *last;
395 394
396 if ((root == NULL) || (root->size == 0) || (root->root == NULL)) 395 if ( (root == NULL) ||
397 return NULL; 396 (root->size == 0) ||
397 (root->root == NULL) )
398 {
399 GNUNET_break (0);
400 return NULL;
401 }
398 402
399 root_node = root->root; 403 root_node = root->root;
400 ret = root_node->element; 404 ret = root_node->element;
401 last = getPos (root, root->size); 405 last = getPos (root, root->size);
402 406
403 if ((root_node == last) && (root->size == 1)) 407 if ( (root_node == last) && (root->size == 1))
404 { 408 {
405 /* We are removing the last node in the heap! */ 409 /* We are removing the last node in the heap! */
410 GNUNET_free (last);
406 root->root = NULL; 411 root->root = NULL;
407 root->traversal_pos = NULL; 412 root->traversal_pos = NULL;
408 GNUNET_assert (0 == --root->size); 413 GNUNET_assert (0 == --root->size);
@@ -418,10 +423,7 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *root)
418 root_node->cost = last->cost; 423 root_node->cost = last->cost;
419 424
420 if (root->traversal_pos == last) 425 if (root->traversal_pos == last)
421 { 426 root->traversal_pos = root->root;
422 root->traversal_pos = root->root;
423 }
424
425 GNUNET_free (last); 427 GNUNET_free (last);
426 root->size--; 428 root->size--;
427 percolateDownHeap (root->root, root); 429 percolateDownHeap (root->root, root);