fix lots of memory leaks in secretsharing decryption
authorFlorian Dold <florian.dold@gmail.com>
Mon, 14 Apr 2014 23:29:44 +0000 (23:29 +0000)
committerFlorian Dold <florian.dold@gmail.com>
Mon, 14 Apr 2014 23:29:44 +0000 (23:29 +0000)
src/secretsharing/gnunet-secretsharing-profiler.c
src/secretsharing/gnunet-service-secretsharing.c

index 5dc649178a5a8dfbc3451347a27956da83f46a56..79fa339cfda28832cf4e728b7c23d105df781bde 100644 (file)
@@ -294,7 +294,7 @@ decrypt_disconnect_adapter(void *cls, void *op_result)
     *dh = NULL;
   }
 
-  GNUNET_assert (NULL == connect_ops[n]);
+  GNUNET_assert (NULL != connect_ops[n]);
   connect_ops[n] = NULL;
 }
 
@@ -493,7 +493,10 @@ handle_shutdown (void *cls,
     unsigned int i;
     for (i = 0; i < num_peers; i++)
       if (NULL != connect_ops[i])
+      {
+        // the disconnect callback will set the op to NULL
         GNUNET_TESTBED_operation_done (connect_ops[i]);
+      }
     GNUNET_free (connect_ops);
   }
 
index f169a1655e811726b291a2c347f89e69129d0567..1e19df5ff861d53447df84d7af2fb8f352584bfa 100644 (file)
@@ -558,6 +558,27 @@ decrypt_session_destroy (struct DecryptSession *ds)
     ds->consensus = NULL;
   }
 
+  if (NULL != ds->info)
+  {
+    unsigned int i;
+    for (i = 0; i < ds->share->num_peers; i++)
+    {
+      if (NULL != ds->info[i].partial_decryption)
+      {
+        gcry_mpi_release (ds->info[i].partial_decryption);
+        ds->info[i].partial_decryption = NULL;
+      }
+    }
+    GNUNET_free (ds->info);
+    ds->info = NULL;
+  }
+
+  if (NULL != ds->share)
+  {
+    GNUNET_SECRETSHARING_share_destroy (ds->share);
+    ds->share = NULL;
+  }
+
   if (NULL != ds->client_mq)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying decrypt MQ\n");
@@ -1429,6 +1450,14 @@ decrypt_conclude (void *cls)
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sent decrypt done to client\n");
 
+  GNUNET_free (indices);
+
+  gcry_mpi_release(lagrange);
+  gcry_mpi_release(m);
+  gcry_mpi_release(tmp);
+  gcry_mpi_release(prod);
+  gcry_mpi_release(c_2);
+
   // FIXME: what if not enough peers participated?
 }
 
@@ -1568,7 +1597,7 @@ decrypt_new_element (void *cls,
                 session->share->my_peer, info - session->info, tmp1_str, tmp2_str);
     GNUNET_free (tmp1_str);
     GNUNET_free (tmp2_str);
-    // return;
+    goto cleanup;
   }
 
 
@@ -1582,12 +1611,22 @@ decrypt_new_element (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "P%u: Received invalid partial decryption from P%u (eqn 2)\n",
                 session->share->my_peer, info - session->info);
-    // return;
+    goto cleanup;
   }
 
 
   GNUNET_CRYPTO_mpi_scan_unsigned (&info->partial_decryption, &d->partial_decryption,
                                    GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
+cleanup:
+  gcry_mpi_release (tmp1);
+  gcry_mpi_release (tmp2);
+  gcry_mpi_release (sigma);
+  gcry_mpi_release (commit1);
+  gcry_mpi_release (commit2);
+  gcry_mpi_release (r);
+  gcry_mpi_release (w);
+  gcry_mpi_release (challenge);
+  gcry_mpi_release (c1);
 }
 
 
@@ -1691,6 +1730,14 @@ insert_decrypt_element (struct DecryptSession *ds)
   GNUNET_CONSENSUS_insert (ds->consensus, &element, NULL, NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Inserting decrypt element done!\n",
               ds->share->my_peer);
+
+  gcry_mpi_release (s);
+  gcry_mpi_release (w);
+  gcry_mpi_release (c1);
+  gcry_mpi_release (beta);
+  gcry_mpi_release (tmp);
+  gcry_mpi_release (challenge);
+  gcry_mpi_release (sigma);
 }