- fix use of uninitialized memory
[oweals/gnunet.git] / src / peerinfo-tool / gnunet-peerinfo.c
index 18e1f8da7a249481cc681664ac198fce494fa548..53c2293d8a8e326b91f30678c6eb8ff526eca764 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001-2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -175,7 +175,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Main state machine task (if active).
  */
-static GNUNET_SCHEDULER_TaskIdentifier tt;
+static struct GNUNET_SCHEDULER_Task * tt;
 
 /**
  * Pending #GNUNET_TRANSPORT_get_hello() operation.
@@ -291,15 +291,19 @@ process_resolved_address (void *cls,
 
   if (NULL != address)
   {
-    if (NULL == ar->result)
+    if (0 != strlen (address))
+    {
+      if (NULL != ar->result)
+        GNUNET_free (ar->result);
       ar->result = GNUNET_strdup (address);
+    }
     return;
   }
   ar->atsc = NULL;
   if (GNUNET_SYSERR == res)
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             _("Failure: Cannot convert address to string for peer `%s'\n"),
-             GNUNET_i2s (&ar->pc->peer));
+                _("Failure: Cannot convert address to string for peer `%s'\n"),
+                GNUNET_i2s (&ar->pc->peer));
   pc->num_addresses++;
   if (pc->num_addresses == pc->address_list_size)
     dump_pc (pc);
@@ -346,6 +350,11 @@ print_address (void *cls,
   ar = &pc->address_list[--pc->off];
   ar->pc = pc;
   ar->expiration = expiration;
+  GNUNET_asprintf (&ar->result,
+                   "%s:%u:%u",
+                   address->transport_name,
+                   address->address_length,
+                   address->local_info);
   ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg,
                                                  address,
                                                  no_resolve,
@@ -626,10 +635,10 @@ shutdown_task (void *cls,
     GNUNET_PEERINFO_add_peer_cancel (ac);
     ac = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != tt)
+  if (NULL != tt)
   {
     GNUNET_SCHEDULER_cancel (tt);
-    tt = GNUNET_SCHEDULER_NO_TASK;
+    tt = NULL;
   }
   if (NULL != pic)
   {
@@ -698,7 +707,7 @@ hello_callback (void *cls,
   }
   my_hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (hello);
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id (hello,
+                 GNUNET_HELLO_get_id (my_hello,
                                       &my_peer_identity));
   GNUNET_TRANSPORT_get_hello_cancel (gh);
   gh = NULL;
@@ -721,9 +730,6 @@ static void
 testservice_task (void *cls,
                   int result)
 {
-  struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
-  char *fn;
-
   if (GNUNET_YES != result)
   {
     FPRINTF (stderr,
@@ -809,7 +815,7 @@ static void
 state_machine (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  tt = GNUNET_SCHEDULER_NO_TASK;
+  tt = NULL;
 
   if (NULL != put_uri)
   {