gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26827 - gnunet/src/peerinfo


From: gnunet
Subject: [GNUnet-SVN] r26827 - gnunet/src/peerinfo
Date: Wed, 10 Apr 2013 11:42:58 +0200

Author: wachs
Date: 2013-04-10 11:42:58 +0200 (Wed, 10 Apr 2013)
New Revision: 26827

Modified:
   gnunet/src/peerinfo/gnunet-service-peerinfo.c
Log:
fix mem leak and counting valid addresses


Modified: gnunet/src/peerinfo/gnunet-service-peerinfo.c
===================================================================
--- gnunet/src/peerinfo/gnunet-service-peerinfo.c       2013-04-10 09:33:35 UTC 
(rev 26826)
+++ gnunet/src/peerinfo/gnunet-service-peerinfo.c       2013-04-10 09:42:58 UTC 
(rev 26827)
@@ -422,16 +422,34 @@
   }
 
   if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_1st))
-       r->hello = hello_clean_1st;
+  {
+       if (NULL == r->hello)
+               r->hello = hello_clean_1st;
+       else
+       {
+                       GNUNET_break (0);
+                       GNUNET_free (r->hello);
+                       r->hello = hello_clean_1st;
+       }
+  }
   else
-       r->friend_only_hello = hello_clean_1st;
+  {
+       if (NULL == r->friend_only_hello)
+               r->friend_only_hello = hello_clean_1st;
+       else
+       {
+                       GNUNET_break (0);
+                       GNUNET_free (r->friend_only_hello);
+                       r->friend_only_hello = hello_clean_1st;
+       }
+  }
 
   if (NULL != hello_2nd)
   {
          hello_clean_2nd = GNUNET_HELLO_iterate_addresses (hello_2nd, 
GNUNET_YES,
                                                                                
                                                                                
                                          &discard_expired, &now);
          left = 0;
-         (void) GNUNET_HELLO_iterate_addresses (hello_2nd, GNUNET_NO,
+         (void) GNUNET_HELLO_iterate_addresses (hello_clean_2nd, GNUNET_NO,
                                                                                
                                                                                
 &count_addresses, &left);
          if (0 == left)
          {
@@ -440,10 +458,28 @@
              GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", 
fn);
          }
 
-         if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean_2nd))
-               r->hello = hello_clean_2nd;
+         if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean_2nd))
+         {
+               if (NULL == r->hello)
+                       r->hello = hello_clean_2nd;
+               else
+               {
+                               GNUNET_break (0);
+                               GNUNET_free (r->hello);
+                               r->hello = hello_clean_2nd;
+               }
+         }
          else
-               r->friend_only_hello = hello_clean_2nd;
+         {
+               if (NULL == r->friend_only_hello)
+                       r->friend_only_hello = hello_clean_2nd;
+               else
+               {
+                               GNUNET_break (0);
+                               GNUNET_free (r->friend_only_hello);
+                               r->friend_only_hello = hello_clean_2nd;
+               }
+         }
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' and `%s' HELLO message in 
file\n",
@@ -482,8 +518,12 @@
     if (NULL != fn)
     {
       read_host_file (fn, GNUNET_YES, &r);
-      entry->hello = r.hello;
-      entry->friend_only_hello = r.friend_only_hello;
+      if (NULL != r.hello)
+       update_hello (identity, r.hello);
+      if (NULL != r.friend_only_hello)
+       update_hello (identity, r.friend_only_hello);
+      GNUNET_free_non_null (r.hello);
+      GNUNET_free_non_null (r.friend_only_hello);
       GNUNET_free (fn);
     }
     notify_all (entry);
@@ -548,7 +588,6 @@
   struct GNUNET_PeerIdentity identity;
   struct ReadHostFileContext r;
   const char *filename;
-  struct HostEntry *entry;
   struct GNUNET_PeerIdentity id_public;
   struct GNUNET_PeerIdentity id_friend;
   struct GNUNET_PeerIdentity id;
@@ -614,18 +653,20 @@
                }
   }
        /* ok, found something valid, remember HELLO */
-  entry = add_host_to_known_hosts (&id);
+  add_host_to_known_hosts (&id);
   if (NULL != r.hello)
   {
                        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer 
`%s' public HELLO \n",
                                        GNUNET_i2s (&id));
        update_hello (&id, r.hello);
+       GNUNET_free (r.hello);
   }
   if (NULL != r.friend_only_hello)
   {
                GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s' friend 
only HELLO \n",
                                        GNUNET_i2s (&id));
        update_hello (&id, r.friend_only_hello);
+       GNUNET_free (r.friend_only_hello);
   }
        dsc->matched++;
        return GNUNET_OK;
@@ -673,6 +714,7 @@
                                                                                
 const struct GNUNET_HELLO_Message *friend_hello)
 {
        struct GNUNET_HELLO_Message * res;
+       struct GNUNET_HELLO_Message * tmp;
        struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
 
        if (NULL != friend_hello)
@@ -683,8 +725,9 @@
        }
 
        GNUNET_HELLO_get_key (hello, &pk);
-       res = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES);
-       res = GNUNET_HELLO_merge (hello, res);
+       tmp = GNUNET_HELLO_create (&pk, NULL, NULL, GNUNET_YES);
+       res = GNUNET_HELLO_merge (hello, tmp);
+       GNUNET_free (tmp);
        GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res));
        return res;
 }
@@ -718,7 +761,7 @@
   GNUNET_assert (NULL != host);
 
   friend_hello_type = GNUNET_HELLO_is_friend_only (hello);
-       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %s HELLO for `%s'\n",
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating %s HELLO for `%s'\n",
                        (GNUNET_YES == friend_hello_type) ? "friend-only" : 
"public",
                        GNUNET_i2s (peer));
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]