X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftestbed%2Fgnunet-service-testbed_cache.c;h=32f63f3e30b2ada0dd96d169bfdd7c91e809ea8b;hb=db9c68c76d7a9eb3f200df9d0fcaf971387cb061;hp=69f820a30cf6d99a5a75ff5555da08c8e267577e;hpb=93ddb2f4a73f7867dc9cc850cccb6c1ab8d23fd0;p=oweals%2Fgnunet.git diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c index 69f820a30..32f63f3e3 100644 --- a/src/testbed/gnunet-service-testbed_cache.c +++ b/src/testbed/gnunet-service-testbed_cache.c @@ -92,8 +92,8 @@ static unsigned int cache_size; /** * Looks up in the cache and returns the entry * - * @param key the peer identity of the peer whose corresponding entry has to be - * looked up + * @param peer_id the peer identity of the peer whose corresponding entry has to + * be looked up * @return the HELLO message; NULL if not found */ static struct CacheEntry * @@ -111,6 +111,20 @@ cache_lookup (unsigned int peer_id) } +/** + * Free the resources occupied by a cache entry + * + * @param entry the cache entry to free + */ +static void +free_entry (struct CacheEntry *entry) +{ + GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, entry); + GNUNET_free_non_null (entry->hello); + GNUNET_free (entry); +} + + /** * Creates a new cache entry and then puts it into the cache's hashtable. * @@ -121,7 +135,7 @@ static struct CacheEntry * add_entry (unsigned int peer_id) { struct CacheEntry *entry; - + GNUNET_assert (NULL != cache); if (cache_size == GNUNET_CONTAINER_multihashmap32_size (cache)) { @@ -131,8 +145,9 @@ add_entry (unsigned int peer_id) GNUNET_CONTAINER_multihashmap32_remove (cache, (uint32_t) entry->peer_id, entry)); + free_entry (entry); } - entry = GNUNET_malloc (sizeof (struct CacheEntry)); + entry = GNUNET_new (struct CacheEntry); entry->peer_id = peer_id; GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap32_put (cache, @@ -162,8 +177,7 @@ cache_clear_iterator (void *cls, uint32_t key, void *value) GNUNET_assert (NULL != entry); GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_remove (cache, key, value)); - GNUNET_free_non_null (entry->hello); - GNUNET_free (entry); + free_entry (entry); return GNUNET_YES; }