Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / c / dht-kademlia / dht-kademlia.c
index ceee01a..9c266fb 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2012-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -27,12 +27,12 @@ static void node(int argc, char* argv[])
   double deadline;
   xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
   /* Node initialization */
-  unsigned int id = strtoul(argv[1], NULL, 0);
+  unsigned int id = (unsigned int)strtoul(argv[1], NULL, 0);
   node_t node     = node_init(id);
 
   if (argc == 4) {
     XBT_INFO("Hi, I'm going to join the network with id %s", sg_mailbox_get_name(node->mailbox));
-    unsigned int id_known = strtoul(argv[2], NULL, 0);
+    unsigned int id_known = (unsigned int)strtoul(argv[2], NULL, 0);
     join_success          = join(node, id_known);
     deadline              = strtod(argv[3], NULL);
   } else {
@@ -58,11 +58,12 @@ static void node(int argc, char* argv[])
         const kademlia_message_t msg = (kademlia_message_t)(node->received_msg);
         if (msg) {
           handle_find_node(node, msg);
-          free(msg->answer);
+          answer_free(msg->answer);
           free(msg);
           node->receive_comm = NULL;
-        } else
+        } else {
           sg_actor_sleep_for(1);
+        }
       } else {
         /* We search for a pseudo random node */
         if (simgrid_get_clock() >= next_lookup_time) {
@@ -77,6 +78,9 @@ static void node(int argc, char* argv[])
   } else {
     XBT_INFO("I couldn't join the network :(");
   }
+  if (node->receive_comm)
+    sg_comm_unref(node->receive_comm);
+
   XBT_DEBUG("I'm leaving the network");
   XBT_INFO("%u/%u FIND_NODE have succeeded", node->find_node_success, node->find_node_success + node->find_node_failed);
   node_free(node);