From 1c2e854307c0bfae10cf3057ffcbd18a922ccab9 Mon Sep 17 00:00:00 2001 From: lurchi Date: Fri, 2 Feb 2018 19:39:30 +0100 Subject: [PATCH] consider deletion of egos we don't know; make code less obscure --- src/social/gnunet-service-social.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 21158acd5..bac08ae9d 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -3599,30 +3599,34 @@ identity_recv_ego (void *cls, struct GNUNET_IDENTITY_Ego *id_ego, GNUNET_CRYPTO_hash (&ego_pub_key, sizeof (ego_pub_key), &ego_pub_hash); struct Ego *ego = GNUNET_CONTAINER_multihashmap_get (egos, &ego_pub_hash); + if (NULL == ego && NULL == name) + { + // an ego that is none of our business has been deleted + return; + } if (NULL != ego) { + // one of our egos has been changed GNUNET_free (ego->name); - if (NULL == name) // deleted + if (NULL == name) { + // one of our egos has been deleted GNUNET_CONTAINER_multihashmap_remove (egos, &ego_pub_hash, ego); GNUNET_free (ego); - ego = NULL; + return; } } else { ego = GNUNET_malloc (sizeof (*ego)); } - if (NULL != ego) - { - ego->key = *(GNUNET_IDENTITY_ego_get_private_key (id_ego)); - size_t name_size = strlen (name) + 1; - ego->name = GNUNET_malloc (name_size); - GNUNET_memcpy (ego->name, name, name_size); + ego->key = *(GNUNET_IDENTITY_ego_get_private_key (id_ego)); + size_t name_size = strlen (name) + 1; + ego->name = GNUNET_malloc (name_size); + GNUNET_memcpy (ego->name, name, name_size); - GNUNET_CONTAINER_multihashmap_put (egos, &ego_pub_hash, ego, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); - } + GNUNET_CONTAINER_multihashmap_put (egos, &ego_pub_hash, ego, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); // FIXME: notify clients about changed ego } -- 2.25.1