X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fcadet%2Fgnunet-service-cadet_peer.c;h=da78a03c400a0e2d680b9273c1fbc63d83614e52;hb=5c8feda7faa01365a1fb6983595ceb65dfe4fb11;hp=c4e2c0ccf3f00be32a27de7b4027f8e8661edd19;hpb=012ff13acc0cb2f5d7210aa48819395fecf12a3d;p=oweals%2Fgnunet.git diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index c4e2c0ccf..da78a03c4 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c @@ -532,49 +532,32 @@ GCP_set_mq (struct CadetPeer *cp, GCP_2s (cp), mq); cp->core_mq = mq; - /* Since these callbacks can remove any items from this list, we must take a - * snapshot and then test each one to see if it's still in the list. */ - int count = 0; - for (struct GCP_MessageQueueManager *mqm = cp->mqm_head; + for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next; NULL != mqm; - mqm = mqm->next) - ++count; - struct GCP_MessageQueueManager *mqms[count]; - int i = 0; - for (struct GCP_MessageQueueManager *mqm = cp->mqm_head; - NULL != mqm; - mqm = mqm->next) - mqms[i++] = mqm; - for (i = 0; i < count; ++i) + mqm = next) { - for (struct GCP_MessageQueueManager *mqm = cp->mqm_head; - NULL != mqm; - mqm = mqm->next) + /* Save next pointer in case mqm gets freed by the callback */ + next = mqm->next; + if (NULL == mq) { - if (mqms[i] != mqm) - continue; - if (NULL == mq) + if (NULL != mqm->env) { - if (NULL != mqm->env) - { - GNUNET_MQ_discard (mqm->env); - mqm->env = NULL; - mqm->cb (mqm->cb_cls, - GNUNET_SYSERR); - } - else - { - mqm->cb (mqm->cb_cls, - GNUNET_NO); - } + GNUNET_MQ_discard (mqm->env); + mqm->env = NULL; + mqm->cb (mqm->cb_cls, + GNUNET_SYSERR); } else { - GNUNET_assert (NULL == mqm->env); mqm->cb (mqm->cb_cls, - GNUNET_YES); + GNUNET_NO); } - break; + } + else + { + GNUNET_assert (NULL == mqm->env); + mqm->cb (mqm->cb_cls, + GNUNET_YES); } } if ( (NULL != mq) || @@ -996,7 +979,7 @@ GCP_attach_path (struct CadetPeer *cp, (desirability < root_desirability) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Decided to not attach path %p to peer %s due to undesirability\n", + "Decided to not attach path %s to peer %s due to undesirability\n", GCPP_2s (path), GCP_2s (cp)); return NULL;