gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [taler-anastasis] 03/06: fix memory leaks
Date: Thu, 22 Oct 2020 18:52:08 +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 281eb08927b8da029ec9e59a5de054cd716e25ec
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Oct 22 14:01:58 2020 +0200

    fix memory leaks
---
 src/backend/anastasis-httpd_truth.c        |  2 +-
 src/backend/anastasis-httpd_truth_upload.c |  4 ---
 src/include/anastasis_database_lib.h       |  2 ++
 src/lib/anastasis.c                        | 46 ++++++++++++++++++------------
 src/lib/anastasis_api_keyshare_lookup.c    | 11 +------
 src/lib/anastasis_api_truth_store.c        | 11 +++++--
 src/lib/testing_api_cmd_keyshare_lookup.c  |  8 ------
 src/lib/testing_api_cmd_truth_store.c      | 23 +++++++--------
 src/lib/testing_cmd_secret_share.c         |  2 ++
 src/stasis/plugin_anastasis_postgres.c     | 34 +++++++++++++++-------
 10 files changed, 76 insertions(+), 67 deletions(-)

diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index 689306f..34afd47 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -811,7 +811,7 @@ AH_handler_truth_get (struct MHD_Connection *connection,
     case ANASTASIS_DB_STATUS_NO_RESULTS:
       GNUNET_free (decrypted_truth);
       return MHD_NO;
-    case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
+    case ANASTASIS_DB_STATUS_VALID_CODE_STORED:
       break;
     default:
       GNUNET_free (decrypted_truth);
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index cfc6793..7a50c70 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -120,10 +120,6 @@ AH_handler_truth_post (struct MHD_Connection *connection,
     res = TALER_MHD_parse_json_data (connection,
                                      json,
                                      spec);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Truth json from upload: %s\nResult: %i\n",
-                json_dumps (json, JSON_COMPACT),
-                res);
 
     if (GNUNET_SYSERR == res)
       return MHD_NO; /* hard failure */
diff --git a/src/include/anastasis_database_lib.h 
b/src/include/anastasis_database_lib.h
index 7c12495..0deb557 100644
--- a/src/include/anastasis_database_lib.h
+++ b/src/include/anastasis_database_lib.h
@@ -55,10 +55,12 @@ enum ANASTASIS_DB_QueryStatus
    * Already valid code stored under this public key, please use the valid code
    */
   ANASTASIS_DB_STATUS_VALID_CODE_STORED = -6,
+
   /**
    * Provided Challenge code didnt match the server generated code
    */
   ANASTASIS_DB_STATUS_CHALLENGE_CODE_MISSMATCH = -5,
+
   /**
    * Update failed because the old recovery data hash does not match what we 
previously had in the DB.
    */
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 6b080ab..11a4c86 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -531,10 +531,6 @@ policy_lookup_cb (void *cls,
                                   JSON_DECODE_ANY,
                                   &json_error);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Recovery_document after json_loadb  %s\n",
-              json_dumps (recovery_document, JSON_COMPACT));
-
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_json ("policies",
                            &dec_policies),
@@ -558,17 +554,12 @@ policy_lookup_cb (void *cls,
     return;
   }
   json_decref (recovery_document);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Decryption Policies after unpack  %s\n",
-              json_dumps (dec_policies, JSON_COMPACT | JSON_SORT_KEYS));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Escrow Methods after unpack  %s\n",
-              json_dumps (esc_methods, JSON_COMPACT | JSON_SORT_KEYS));
+  GNUNET_JSON_parse_free (spec);
 
   r->ri->cs_len = json_array_size (esc_methods);
   r->ri->dps_len = json_array_size (dec_policies);
-  r->ri->dps = GNUNET_new_array (r->ri->dps_len, struct
-                                 ANASTASIS_DecryptionPolicy);
+  r->ri->dps = GNUNET_new_array (r->ri->dps_len,
+                                 struct ANASTASIS_DecryptionPolicy);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d encrypted core secret is %s-%llu b\n", __FILE__,
@@ -799,7 +790,13 @@ ANASTASIS_recovery_abort (struct ANASTASIS_Recovery *r)
     ANASTASIS_policy_lookup_cancel (r->plo);
     r->plo = NULL;
   }
+  if (NULL != r->encrypted_recovery_document)
+  {
+    GNUNET_free (r->encrypted_recovery_document);
+    r->encrypted_recovery_document = NULL;
+  }
   GNUNET_free (r);
+  r = NULL;
 }
 
 
@@ -1805,11 +1802,6 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
         return NULL;
       }
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Esc methods json append before upload %d: %s\n",
-                  l,
-                  json_dumps (esc_methods, JSON_COMPACT));
-
       // prepares policy store operation
       int contains_url = 0;
       for (unsigned int j = 0; j < ss->pss_length; j++)
@@ -1930,5 +1922,23 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
 void
 ANASTASIS_secret_share_cancel (struct ANASTASIS_SecretShare *ss)
 {
-  // FIXME: implement!
+  for (unsigned int i = 0; i < ss->pss_length; i++)
+  {
+    if (NULL != ss->pss[i]->recovery_data)
+    {
+      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;
+    }
+  }
+
 }
diff --git a/src/lib/anastasis_api_keyshare_lookup.c 
b/src/lib/anastasis_api_keyshare_lookup.c
index 2666a06..06111ad 100644
--- a/src/lib/anastasis_api_keyshare_lookup.c
+++ b/src/lib/anastasis_api_keyshare_lookup.c
@@ -282,10 +282,6 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context *ctx,
   }
   kslo = GNUNET_new (struct ANASTASIS_KeyShareLookupOperation);
   kslo->ctx = ctx;
-  /** FIXME duplicate? see line 323
-  kslo->cb = cb;
-  kslo->cb_cls = cb_cls;
-  */
   kslo->truth_key = truth_key;
   char *pub_key_str;
 
@@ -294,20 +290,14 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context 
*ctx,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "truth public key in keyshare lookup:  %s\n",
               pub_key_str);
-  /*FIXME */
-
-
-
   GNUNET_asprintf (&path,
                    "truth/%s",
                    pub_key_str);
-
   kslo->url = TALER_url_join (backend_url,
                               path,
                               "response",
                               answer,
                               NULL);
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Url get request (keyshare lookup): %s\n",
               kslo->url);
@@ -327,6 +317,7 @@ ANASTASIS_keyshare_lookup (struct GNUNET_CURL_Context *ctx,
                                        &handle_keyshare_lookup_finished,
                                        kslo);
   GNUNET_free (path);
+  GNUNET_free (pub_key_str);
   curl_slist_free_all (job_headers);
   return kslo;
 }
diff --git a/src/lib/anastasis_api_truth_store.c 
b/src/lib/anastasis_api_truth_store.c
index e010315..87134a5 100644
--- a/src/lib/anastasis_api_truth_store.c
+++ b/src/lib/anastasis_api_truth_store.c
@@ -61,6 +61,11 @@ struct ANASTASIS_TruthStoreOperation
    */
   void *cb_cls;
 
+  /**
+   * Reference to data (for cleanup).
+   */
+  char *data;
+
   /**
    * Payment URI we received from the service, or NULL.
    */
@@ -83,6 +88,7 @@ ANASTASIS_truth_store_cancel (struct
   }
   GNUNET_free (tso->pay_uri);
   GNUNET_free (tso->url);
+  GNUNET_free (tso->data);
   GNUNET_free (tso);
 }
 
@@ -271,9 +277,6 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
   CURL *eh;
   char *json_str;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 3: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
   json_str = json_dumps (truth_data,
                          JSON_COMPACT);
 
@@ -313,6 +316,7 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
                                    paid_order_id,
                                    NULL);
       GNUNET_free (path);
+      GNUNET_free (pub_key_str);
     }
     else
     {
@@ -325,6 +329,7 @@ ANASTASIS_truth_store (struct GNUNET_CURL_Context *ctx,
               "URL before curl:  %s\n",
               tso->url);
   tso->ctx = ctx;
+  tso->data = json_str;
   tso->cb = cb;
   tso->cb_cls = cb_cls;
   eh = ANASTASIS_curl_easy_get_ (tso->url);
diff --git a/src/lib/testing_api_cmd_keyshare_lookup.c 
b/src/lib/testing_api_cmd_keyshare_lookup.c
index f1bb85f..68fea91 100644
--- a/src/lib/testing_api_cmd_keyshare_lookup.c
+++ b/src/lib/testing_api_cmd_keyshare_lookup.c
@@ -153,14 +153,6 @@ keyshare_lookup_run (void *cls,
     }
   }
 
-  char *pub_key_str;
-  pub_key_str = GNUNET_STRINGS_data_to_string_alloc (ksls->truth_public_key,
-                                                     sizeof (*ksls->
-                                                             
truth_public_key));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "truth public key in keyshare testing cmd:  %s\n",
-              pub_key_str);
-
   ksls->kslo = ANASTASIS_keyshare_lookup (is->ctx,
                                           ksls->anastasis_url,
                                           ksls->truth_public_key,
diff --git a/src/lib/testing_api_cmd_truth_store.c 
b/src/lib/testing_api_cmd_truth_store.c
index 13bd789..46ef43f 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -180,7 +180,9 @@ truth_store_cb (void *cls,
         return;
       }
     case ANASTASIS_US_HTTP_ERROR:
-      break;
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (tss->is);
+      return;
     case ANASTASIS_US_CLIENT_ERROR:
       GNUNET_break (0);
       TALER_TESTING_interpreter_fail (tss->is);
@@ -213,9 +215,7 @@ truth_store_run (void *cls,
 {
   struct TruthStoreState *tss = cls;
   tss->is = is;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 2: %s\n",
-              json_dumps (tss->truth_data, JSON_COMPACT));
+
   if (NULL != tss->prev_upload)
   {
     const struct TALER_TESTING_Command *ref;
@@ -307,9 +307,13 @@ truth_store_cleanup (void *cls,
     ANASTASIS_truth_store_cancel (tss->tso);
     tss->tso = NULL;
   }
-
-  GNUNET_free (tss->payment_order_id);
+  if (NULL != tss->payment_order_id)
+  {
+    GNUNET_free (tss->payment_order_id);
+    tss->payment_order_id = NULL;
+  }
   GNUNET_free (tss);
+  tss = NULL;
 }
 
 
@@ -425,9 +429,6 @@ ANASTASIS_TESTING_make_truth_example (
                           "truth_mime", mime_type
                           );
   GNUNET_assert (NULL != truth_data);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 0: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
   GNUNET_free (encrypted_truth);
   return truth_data;
 }
@@ -455,10 +456,6 @@ ANASTASIS_TESTING_cmd_truth_store (const char *label,
 {
   struct TruthStoreState *tss;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Truth json before upload 1: %s\n",
-              json_dumps (truth_data, JSON_COMPACT));
-
   tss = GNUNET_new (struct TruthStoreState);
   tss->truth_data = truth_data;
   tss->http_status = http_status;
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index cbf87bc..ac8bca1 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -390,7 +390,9 @@ secret_share_cleanup (void *cls,
   struct SecretShareState *sss = cls;
 
   GNUNET_free (sss->cmd_label_array);
+  sss->cmd_label_array = NULL;
   GNUNET_free (sss);
+  sss = NULL;
 }
 
 
diff --git a/src/stasis/plugin_anastasis_postgres.c 
b/src/stasis/plugin_anastasis_postgres.c
index aca4ba5..389041d 100644
--- a/src/stasis/plugin_anastasis_postgres.c
+++ b/src/stasis/plugin_anastasis_postgres.c
@@ -521,7 +521,6 @@ postgres_store_recovery_document (void *cls,
     (*version)++;
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -588,7 +587,6 @@ postgres_store_recovery_document (void *cls,
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_SOFT_ERROR:
-    // FIXME: or: retry internally?
     rollback (pg);
     return qs;
   case ANASTASIS_DB_STATUS_NO_RESULTS:
@@ -602,7 +600,6 @@ postgres_store_recovery_document (void *cls,
                 postcounter);
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -643,7 +640,6 @@ postgres_store_recovery_document (void *cls,
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
   default:
-    // FIXME: Some Action
     rollback (pg);
     return qs;
   }
@@ -1306,7 +1302,7 @@ postgres_store_truth (void *cls,
   case ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT:
     break;
   default:
-    // FIXME: Some Action
+    rollback (pg);
     return qs;
   }
 
@@ -1378,6 +1374,7 @@ postgres_get_key_share (void *cls,
                         void **key_share,
                         size_t *key_share_size)
 {
+  enum ANASTASIS_DB_QueryStatus qs;
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (truth_public_key),
@@ -1391,10 +1388,25 @@ postgres_get_key_share (void *cls,
   };
 
   check_connection (pg);
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "key_share_select",
-                                                   params,
-                                                   rs);
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "key_share_select",
+                                                 params,
+                                                 rs);
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    return ANASTASIS_DB_STATUS_SOFT_ERROR;
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    return ANASTASIS_DB_STATUS_NO_RESULTS;
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
+  default:
+    GNUNET_break (0);
+    return ANASTASIS_DB_STATUS_HARD_ERROR;
+  }
 }
 
 
@@ -1440,9 +1452,9 @@ postgres_lookup_account (void *cls,
   switch (qs)
   {
   case GNUNET_DB_STATUS_HARD_ERROR:
+    GNUNET_break (0);
     return ANASTASIS_DB_STATUS_HARD_ERROR;
   case GNUNET_DB_STATUS_SOFT_ERROR:
-    GNUNET_break (0);
     return ANASTASIS_DB_STATUS_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     break; /* handle interesting case below */
@@ -1905,6 +1917,7 @@ postgres_store_challenge_code (void *cls,
   return ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT;
 }
 
+
 /**
  * FIXME maybe implemented in the postgres_gc but want it seperate first
  * Function called to remove all expired codes in the database
@@ -1927,6 +1940,7 @@ postgres_challenge_gc (void *cls)
                                              params);
 }
 
+
 /**
  * Initialize Postgres database subsystem.
  *

-- 
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]