Begone foul memory leaks!
authorPhilipp Tölke <toelke@in.tum.de>
Mon, 21 Feb 2011 10:03:43 +0000 (10:03 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Mon, 21 Feb 2011 10:03:43 +0000 (10:03 +0000)
src/vpn/gnunet-daemon-exit.c
src/vpn/gnunet-daemon-vpn.c

index e75e1e6cd31cb31ea5b0692b9d3268172eef8264..da8392ebe5074938d3dac697991094fddc736892 100644 (file)
@@ -124,6 +124,16 @@ struct udp_state
  */
 static struct GNUNET_CONTAINER_MultiHashMap *udp_services;
 
+/**
+ * Function that frees everything from a hashmap
+ */
+static int
+free_iterate(void* cls, const GNUNET_HashCode* hash, void* value)
+{
+  GNUNET_free(value);
+  return GNUNET_YES;
+}
+
 /**
  * Function scheduled as very last function, cleans up after us
  */
@@ -131,6 +141,10 @@ static void
 cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
     GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
 
+    GNUNET_CONTAINER_multihashmap_iterate(udp_connections,
+                                          free_iterate,
+                                          NULL);
+
     if (mesh_handle != NULL)
       {
        GNUNET_MESH_disconnect(mesh_handle);
@@ -501,6 +515,8 @@ receive_udp_service (void *cls,
       GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4MASK", &ipv4mask));
       inet_pton(AF_INET, ipv4addr, &tmp);
       inet_pton(AF_INET, ipv4mask, &tmp2);
+      GNUNET_free(ipv4addr);
+      GNUNET_free(ipv4mask);
 
       /* This should be a noop */
       tmp = tmp & tmp2;
@@ -586,6 +602,8 @@ receive_udp_service (void *cls,
       GNUNET_CONTAINER_multihashmap_contains (udp_connections, &hash))
     GNUNET_CONTAINER_multihashmap_put (udp_connections, &hash, state,
                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  else
+    GNUNET_free(state);
 
   (void)GNUNET_DISK_file_write(helper_handle->fh_to_helper, buf, len);
   return GNUNET_YES;
index 84adcd975e45ce5a3ee83beb1f0e914ac93a3d07..d22062074215b8659b0a2a3632a8a5ccb3dc5aae 100644 (file)
@@ -272,6 +272,7 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
                                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
          {
            GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not store to hashmap\n");
+            GNUNET_free(value);
          }