-rps: proper destruction of sampler elements
authorJulius Bünger <buenger@mytum.de>
Tue, 6 Sep 2016 14:05:44 +0000 (14:05 +0000)
committerJulius Bünger <buenger@mytum.de>
Tue, 6 Sep 2016 14:05:44 +0000 (14:05 +0000)
src/rps/gnunet-service-rps_sampler.c
src/rps/gnunet-service-rps_sampler_elem.c
src/rps/gnunet-service-rps_sampler_elem.h
src/rps/test_rps.c

index 95aabc21aa2b42a44daeb99bc52f2c040f6ec2b9..cfc5ce77b9e19c20b1f91960deb30bdeae5c2a30 100644 (file)
@@ -327,7 +327,7 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
                "-%" PRIu32 ": %s",
                i,
                sampler->sampler_elements[i]->file_name);
-      GNUNET_free (sampler->sampler_elements[i]);
+      RPS_sampler_elem_destroy (sampler->sampler_elements[i]);
     }
 
     GNUNET_array_grow (sampler->sampler_elements,
index c22ed564b6a2a53970cd18d8adb46f87c14565fe..007f818e289fceb7a4ceb65be6e294d0dc8cbfdc 100644 (file)
@@ -98,6 +98,24 @@ RPS_sampler_elem_create (void)
 }
 
 
+/**
+ * Destroy a sampler element.
+ *
+ * @param sampler_elem the element to destroy
+ */
+void
+RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem)
+{
+  #ifdef TO_FILE
+  if (NULL != sampler_elem->file_name)
+  {
+    GNUNET_free (sampler_elem->file_name);
+  }
+  #endif /* TO_FILE */
+  GNUNET_free (sampler_elem);
+}
+
+
 /**
  * Input an PeerID into the given sampler element.
  *
@@ -112,9 +130,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
 
   s_elem->num_peers++;
 
+  #ifdef TO_FILE
   to_file (s_elem->file_name,
            "Got id %s",
            GNUNET_i2s_full (other));
+  #endif /* TO_FILE */
 
   if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id)))
   {
@@ -155,9 +175,11 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
   }
   s_elem->is_empty = NOT_EMPTY;
 
+  #ifdef TO_FILE
   to_file (s_elem->file_name,
            "Now holding %s",
            GNUNET_i2s_full (&s_elem->peer_id));
+  #endif /* TO_FILE */
 }
 
 /**
index 861a579bc0b8bbafb5f24443485f322d1b6078aa..bbf2c147bd6b77a0f5e7040abe74e0028f5a6781 100644 (file)
@@ -119,6 +119,15 @@ struct RPS_SamplerElement *
 RPS_sampler_elem_create (void);
 
 
+/**
+ * Destroy a sampler element.
+ *
+ * @param sampler_elem the element to destroy
+ */
+void
+RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem);
+
+
 /**
  * Input an PeerID into the given sampler element.
  *
index e0fbdbb887ae214d6af6c53a2e16548d449dd264..629b73d443f148710aa42850a33325674cbe8165 100644 (file)
@@ -1292,6 +1292,7 @@ file_name_cb (void *cls, const char *filename)
     {
       RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
     }
+    RPS_sampler_elem_destroy (s_elem);
   }
   return GNUNET_OK;
 }