gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 04/06: fix memory leaks


From: gnunet
Subject: [taler-anastasis] 04/06: fix memory leaks
Date: Thu, 22 Oct 2020 18:52:09 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 1ba736f0e171f8cdd2cda1be489ed7bf782a5d7b
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Oct 22 17:47:28 2020 +0200

    fix memory leaks
---
 src/lib/anastasis.c                    | 89 +++++++++++++++++++++++-----------
 src/lib/testing_api_cmd_policy_store.c |  2 +-
 src/lib/testing_cmd_policy_create.c    |  5 +-
 src/lib/testing_cmd_truth_upload.c     |  9 +++-
 4 files changed, 74 insertions(+), 31 deletions(-)

diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 11a4c86..68a1b46 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -530,6 +530,7 @@ policy_lookup_cb (void *cls,
                                   size_plaintext,
                                   JSON_DECODE_ANY,
                                   &json_error);
+  GNUNET_free (plaintext);
 
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_json ("policies",
@@ -1091,6 +1092,8 @@ ANASTASIS_truth_upload (struct GNUNET_CURL_Context *ctx,
                      "encrypted_truth", GNUNET_JSON_from_data (
                        encrypted_truth, encrypted_truth_size),
                      "truth_mime", mime_type);
+  GNUNET_free (encrypted_key_share);
+  GNUNET_free (encrypted_truth);
   if (NULL == truth)
   {
     GNUNET_break (0);
@@ -1268,7 +1271,11 @@ ANASTASIS_policy_create (const struct ANASTASIS_Truth 
*truths[],
 void
 ANASTASIS_policy_destroy (struct ANASTASIS_Policy *p)
 {
+  GNUNET_free (p->truths);
+  p->truths = NULL;
+
   GNUNET_free (p);
+  p = NULL;
 }
 
 
@@ -1382,26 +1389,32 @@ struct ANASTASIS_SecretShare
    * Callback which gives back the payment details
    */
   ANASTASIS_SharePaymentCallback spc;
+
   /**
    * Closure for the payment callback
    */
   void *spc_cls;
+
   /**
    * Callback which gives back the result of the POST Request
    */
   ANASTASIS_ShareResultCallback src;
+
   /**
    * Closure for the Result Callback
    */
   void *src_cls;
+
   /**
    * Closure for the Result Callback
    */
   struct GNUNET_CURL_Context *ctx;
+
   /**
    * References for the upload states and operations (size of truths passed)
    */
   struct PolicyStoreState **pss;
+
   /**
    * Closure for the Result Callback
    */
@@ -1409,6 +1422,32 @@ struct ANASTASIS_SecretShare
 };
 
 
+/**
+ * Free the state of a "policy store" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ */
+static void
+policy_store_cleanup (void *cls)
+{
+  struct PolicyStoreState *pss = cls;
+
+  if (NULL != pss->pso)
+  {
+    ANASTASIS_policy_store_cancel (pss->pso);
+    pss->pso = NULL;
+  }
+  if (NULL != pss->recovery_data)
+  {
+    GNUNET_free (pss->recovery_data);
+    pss->recovery_data = NULL;
+  }
+  GNUNET_free (pss);
+  pss = NULL;
+}
+
+
 static void
 policy_store_cb (void *cls,
                  enum ANASTASIS_ErrorCode ec,
@@ -1481,6 +1520,8 @@ policy_store_cb (void *cls,
                         ec);
           pss->ss->spc = NULL;
         }
+        ANASTASIS_secret_share_cancel (pss->ss);
+        policy_store_cleanup (pss);
       }
       return;
     case ANASTASIS_US_CONFLICTING_POLICY:
@@ -1507,7 +1548,8 @@ policy_store_cb (void *cls,
                     http_status);
       pss->ss->src = NULL;
     }
-
+    ANASTASIS_secret_share_cancel (pss->ss);
+    policy_store_cleanup (pss);
   }
 }
 
@@ -1708,6 +1750,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       GNUNET_strlcpy (nonces + b * strlen (nonce_str),
                       nonce_str,
                       strlen (nonce_str));
+      GNUNET_free (nonce_str);
     }
 
     nonces[52 * policies[k]->nonces_length] = '\0';
@@ -1737,11 +1780,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       return NULL;
     }
 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Dec policies json append before upload %d: %s\n",
-                k,
-                json_dumps (dec_policies, JSON_COMPACT));
-
     // FIXME CHALLENGE
     for (unsigned int l = 0; l < policies[k]->nonces_length; l++)
     {
@@ -1803,7 +1841,7 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
       }
 
       // prepares policy store operation
-      int contains_url = 0;
+      bool contains_url = false;
       for (unsigned int j = 0; j < ss->pss_length; j++)
       {
         if (NULL != ss->pss[j]->anastasis_url)
@@ -1811,12 +1849,12 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
           if (0 == strcmp (ss->pss[j]->anastasis_url,
                            policies[k]->truths[l]->url))
           {
-            contains_url = 1;
+            contains_url = true;
             break;
           }
         }
       }
-      if (0 == contains_url)
+      if (! contains_url)
       {
         ss->pss[index_pss]->anastasis_url = policies[k]->truths[l]->url;
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1854,10 +1892,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
     "core_secret", GNUNET_JSON_from_data (encrypted_core_secret,
                                           core_secret_size));
   GNUNET_assert (NULL != recovery_document);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "recovery document json before upload: %s\n",
-              json_dumps (recovery_document,
-                          JSON_COMPACT | JSON_SORT_KEYS));
 
   // FIXME COMPRESSION
   recovery_document_str = json_dumps (recovery_document,
@@ -1882,6 +1916,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                                                 recovery_document_size,
                                                 &ss->pss[l]->recovery_data,
                                                 
&ss->pss[l]->recovery_data_size);
+    GNUNET_free (recovery_document_str);
+    recovery_document_str = NULL;
     // hash recovery data
     GNUNET_CRYPTO_hash (ss->pss[l]->recovery_data,
                         ss->pss[l]->recovery_data_size,
@@ -1922,23 +1958,20 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
 void
 ANASTASIS_secret_share_cancel (struct ANASTASIS_SecretShare *ss)
 {
-  for (unsigned int i = 0; i < ss->pss_length; i++)
+  if (NULL != ss)
   {
-    if (NULL != ss->pss[i]->recovery_data)
+    if (NULL != ss->pss)
     {
-      GNUNET_free (ss->pss[i]->recovery_data);
-      ss->pss[i]->recovery_data = NULL;
-    }
-    if (NULL != ss->pss[i]->ss)
-    {
-      GNUNET_free (ss->pss[i]->ss);
-      ss->pss[i]->ss = NULL;
-    }
-    if (NULL != ss->pss[i])
-    {
-      GNUNET_free (ss->pss[i]);
-      ss->pss[i] = NULL;
+      for (unsigned int i = 0; i< ss->pss_length; i++)
+      {
+        if (NULL != ss->pss[i])
+        {
+          GNUNET_free (ss->pss[i]);
+          ss->pss[i] = NULL;
+        }
+      }
     }
+    GNUNET_free (ss);
+    ss = NULL;
   }
-
 }
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index c200151..d573530 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -404,7 +404,7 @@ policy_store_run (void *cls,
 
 
 /**
- * Free the state of a "policy sore" CMD, and possibly
+ * Free the state of a "policy store" CMD, and possibly
  * cancel it if it did not complete.
  *
  * @param cls closure.
diff --git a/src/lib/testing_cmd_policy_create.c 
b/src/lib/testing_cmd_policy_create.c
index 07d3a66..c685ade 100644
--- a/src/lib/testing_cmd_policy_create.c
+++ b/src/lib/testing_cmd_policy_create.c
@@ -55,7 +55,7 @@ struct PolicyCreateState
   /**
    * Policy object
    */
-  const struct ANASTASIS_Policy *policy;
+  struct ANASTASIS_Policy *policy;
 };
 
 
@@ -118,6 +118,7 @@ policy_create_run (void *cls,
 
   pcs->policy = ANASTASIS_policy_create (truths,
                                          pcs->cmd_label_array_length);
+
   if (NULL == pcs->policy)
   {
     GNUNET_break (0);
@@ -142,7 +143,9 @@ policy_create_cleanup (void *cls,
   struct PolicyCreateState *pcs = cls;
 
   GNUNET_free (pcs->cmd_label_array);
+  ANASTASIS_policy_destroy (pcs->policy);
   GNUNET_free (pcs);
+  pcs = NULL;
 }
 
 
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index fae9492..b73bbc4 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -106,7 +106,7 @@ struct TruthUploadState
   /**
    * Truth object
    */
-  const struct ANASTASIS_Truth *truth;
+  struct ANASTASIS_Truth *truth;
 };
 
 
@@ -243,6 +243,13 @@ truth_upload_cleanup (void *cls,
     ANASTASIS_truth_upload_cancel (tus->tuo);
     tus->tuo = NULL;
   }
+  if (NULL != tus->id_data)
+    json_decref ((json_t *) tus->id_data);
+  if (NULL != tus->truth)
+  {
+    GNUNET_free (tus->truth);
+    tus->truth = NULL;
+  }
   GNUNET_free (tus);
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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