gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 02/02: fix memory leaks


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 02/02: fix memory leaks
Date: Tue, 18 Jun 2019 14:54:12 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 36ceb8795a77090a0b9a78f24f0d01e2ea93220a
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jun 18 14:54:01 2019 +0200

    fix memory leaks
---
 src/lib/merchant_api_pay.c           | 27 +++++++++----------
 src/lib/merchant_api_proposal.c      |  2 +-
 src/lib/merchant_api_refund.c        | 12 ++++-----
 src/lib/merchant_api_tip_authorize.c |  2 +-
 src/lib/merchant_api_tip_pickup.c    |  2 +-
 src/lib/testing_api_cmd_pay.c        |  8 +++---
 src/lib/testing_api_cmd_refund.c     |  4 ++-
 src/lib/testing_api_cmd_tip.c        | 50 ++++++++++++++++++++++++++++--------
 8 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index e583601..a4b4baf 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -116,7 +116,7 @@ struct TALER_MERCHANT_Pay
  */
 static int
 check_abort_refund (struct TALER_MERCHANT_Pay *ph,
-                   const json_t *json)
+                    const json_t *json)
 {
   json_t *refunds;
   unsigned int num_refunds;
@@ -145,11 +145,11 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
       json_t *refund = json_array_get (refunds, i);
       struct GNUNET_JSON_Specification spec_detail[] = {
         GNUNET_JSON_spec_fixed_auto ("merchant_sig",
-                                    sig),
+                                     sig),
         GNUNET_JSON_spec_fixed_auto ("coin_pub",
-                                    &res[i].coin_pub),
-       GNUNET_JSON_spec_uint64 ("rtransaction_id",
-                                &res[i].rtransaction_id),
+                                     &res[i].coin_pub),
+        GNUNET_JSON_spec_uint64 ("rtransaction_id",
+                                 &res[i].rtransaction_id),
         GNUNET_JSON_spec_end()
       };
       struct TALER_RefundRequestPS rr;
@@ -161,7 +161,7 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
                              NULL, NULL))
       {
         GNUNET_break_op (0);
-       GNUNET_JSON_parse_free (spec);
+        GNUNET_JSON_parse_free (spec);
         return GNUNET_SYSERR;
       }
 
@@ -190,19 +190,19 @@ check_abort_refund (struct TALER_MERCHANT_Pay *ph,
       }
       if (-1 == found)
       {
-       GNUNET_break_op (0);
-       return GNUNET_SYSERR;
+        GNUNET_break_op (0);
+        return GNUNET_SYSERR;
       }
 
       if (GNUNET_OK !=
-         GNUNET_CRYPTO_eddsa_verify
+          GNUNET_CRYPTO_eddsa_verify
             (TALER_SIGNATURE_MERCHANT_REFUND,
             &rr.purpose,
             &sig->eddsa_sig,
             &merchant_pub.eddsa_pub))
       {
-       GNUNET_break_op (0);
-       return GNUNET_SYSERR;
+        GNUNET_break_op (0);
+        return GNUNET_SYSERR;
       }
     }
     ph->abort_cb (ph->abort_cb_cls,
@@ -363,8 +363,8 @@ handle_pay_finished (void *cls,
       if (GNUNET_OK != check_forbidden (ph,
                                        json))
       {
-       GNUNET_break_op (0);
-       response_code = 0;
+        GNUNET_break_op (0);
+        response_code = 0;
       }
       break;
     case MHD_HTTP_UNAUTHORIZED:
@@ -954,6 +954,7 @@ TALER_MERCHANT_pay_cancel (struct TALER_MERCHANT_Pay *pay)
     GNUNET_CURL_job_cancel (pay->job);
     pay->job = NULL;
   }
+  TALER_curl_easy_post_finished (&pay->post_ctx);
   GNUNET_free (pay->coins);
   GNUNET_free (pay->url);
   GNUNET_free (pay->post_ctx.json_enc);
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index 37fbc8c..3b48c50 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -447,7 +447,7 @@ TALER_MERCHANT_proposal_cancel
     po->job = NULL;
   }
   GNUNET_free (po->url);
-  GNUNET_free (po->post_ctx.json_enc);
+  TALER_curl_easy_post_finished (&po->post_ctx);
   GNUNET_free (po);
 }
 
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index ab95586..131ca19 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -145,7 +145,7 @@ handle_refund_increase_finished (void *cls,
          "error", &error,
          "code", &code,
          "hint", &hint))
-    
+
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "/refund failed (HTTP code: %lu), backend did "
@@ -175,6 +175,7 @@ TALER_MERCHANT_refund_increase_cancel (struct 
TALER_MERCHANT_RefundIncreaseOpera
     GNUNET_CURL_job_cancel (rio->job);
     rio->job = NULL;
   }
+  TALER_curl_easy_post_finished (&rio->post_ctx);
   GNUNET_free (rio->url);
   GNUNET_free (rio->post_ctx.json_enc);
   GNUNET_free (rio);
@@ -246,7 +247,7 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context 
*ctx,
 /**
  * Cancel a /refund lookup operation
  *
- * @param 
+ * @param
  */
 void
 TALER_MERCHANT_refund_lookup_cancel (struct 
TALER_MERCHANT_RefundLookupOperation *rlo)
@@ -256,7 +257,6 @@ TALER_MERCHANT_refund_lookup_cancel (struct 
TALER_MERCHANT_RefundLookupOperation
     GNUNET_CURL_job_cancel (rlo->job);
     rlo->job = NULL;
   }
-  
   GNUNET_free (rlo->url);
   GNUNET_free (rlo);
 }
@@ -307,7 +307,7 @@ handle_refund_lookup_finished (void *cls,
                   error,
                   code);
       break;
-    } 
+    }
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed /refund lookup, backend did not give"
                 " a valid error object, HTTP code was %lu\n",
@@ -344,7 +344,7 @@ TALER_MERCHANT_refund_lookup (struct GNUNET_CURL_Context 
*ctx,
   rlo->ctx = ctx;
   rlo->cb = cb;
   rlo->cb_cls = cb_cls;
-  
+
   base = TALER_url_join (backend_url, "/public/refund", NULL);
   GNUNET_asprintf (&rlo->url,
                    "%s?instance=%s&order_id=%s",
@@ -369,7 +369,7 @@ TALER_MERCHANT_refund_lookup (struct GNUNET_CURL_Context 
*ctx,
   {
     GNUNET_break (0);
     return NULL;
-  
+
   }
 
   return rlo;
diff --git a/src/lib/merchant_api_tip_authorize.c 
b/src/lib/merchant_api_tip_authorize.c
index 9286443..88b499f 100644
--- a/src/lib/merchant_api_tip_authorize.c
+++ b/src/lib/merchant_api_tip_authorize.c
@@ -266,7 +266,7 @@ TALER_MERCHANT_tip_authorize_cancel (struct 
TALER_MERCHANT_TipAuthorizeOperation
     GNUNET_CURL_job_cancel (tao->job);
     tao->job = NULL;
   }
-  GNUNET_free_non_null (tao->post_ctx.json_enc);
+  TALER_curl_easy_post_finished (&tao->post_ctx);
   GNUNET_free (tao->url);
   GNUNET_free (tao);
 }
diff --git a/src/lib/merchant_api_tip_pickup.c 
b/src/lib/merchant_api_tip_pickup.c
index 63b0e59..99863cb 100644
--- a/src/lib/merchant_api_tip_pickup.c
+++ b/src/lib/merchant_api_tip_pickup.c
@@ -329,7 +329,7 @@ TALER_MERCHANT_tip_pickup_cancel (struct 
TALER_MERCHANT_TipPickupOperation *tpo)
     GNUNET_CURL_job_cancel (tpo->job);
     tpo->job = NULL;
   }
-  GNUNET_free_non_null (tpo->post_ctx.json_enc);
+  TALER_curl_easy_post_finished (&tpo->post_ctx);
   GNUNET_free (tpo->url);
   GNUNET_free (tpo);
 }
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index b3a0e18..68e8b22 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -689,9 +689,9 @@ pay_abort_cb (void *cls,
     pas->res = GNUNET_new_array
       (num_refunds, struct TALER_MERCHANT_RefundEntry);
 
-    memcpy (pas->res, res,
-           num_refunds * sizeof
-              (struct TALER_MERCHANT_RefundEntry));
+    memcpy (pas->res,
+            res,
+            num_refunds * sizeof (struct TALER_MERCHANT_RefundEntry));
     pas->h_contract = *h_contract;
     pas->merchant_pub = *merchant_pub;
   }
@@ -1073,7 +1073,7 @@ pay_abort_cleanup (void *cls,
                   pas->is));
     TALER_MERCHANT_pay_cancel (pas->pao);
   }
-
+  GNUNET_free_non_null (pas->res);
   GNUNET_free (pas);
 }
 
diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c
index bc96175..abe68f8 100644
--- a/src/lib/testing_api_cmd_refund.c
+++ b/src/lib/testing_api_cmd_refund.c
@@ -285,7 +285,6 @@ refund_lookup_cb (void *cls,
   if (rls->http_code != http_status)
     TALER_TESTING_FAIL (rls->is);
 
-  map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
   arr = json_object_get (obj, "refund_permissions");
   if (NULL == arr)
   {
@@ -294,6 +293,7 @@ refund_lookup_cb (void *cls,
     TALER_TESTING_interpreter_next (rls->is);
     return;
   }
+  map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
 
   /* Put in array every refunded coin.  */
   json_array_foreach (arr, index, elem)
@@ -353,6 +353,7 @@ refund_lookup_cb (void *cls,
       TALER_LOG_ERROR ("Bad reference `%s'\n",
                        icoin_reference);
       TALER_TESTING_interpreter_fail (rls->is);
+      GNUNET_CONTAINER_multihashmap_destroy (map);
       return;
     }
 
@@ -364,6 +365,7 @@ refund_lookup_cb (void *cls,
                       " priv trait\n",
                       icoin_reference);
      TALER_TESTING_interpreter_fail (rls->is);
+     GNUNET_CONTAINER_multihashmap_destroy (map);
      return;
     }
 
diff --git a/src/lib/testing_api_cmd_tip.c b/src/lib/testing_api_cmd_tip.c
index cc51ff0..6e1f529 100644
--- a/src/lib/testing_api_cmd_tip.c
+++ b/src/lib/testing_api_cmd_tip.c
@@ -556,9 +556,15 @@ tip_query_cb (void *cls,
   {
     GNUNET_assert (GNUNET_OK == TALER_string_to_amount
       (tqs->expected_amount_available, &a));
-    TALER_LOG_INFO ("expected available %s, actual %s\n",
-                    TALER_amount_to_string (&a),
-                    TALER_amount_to_string (amount_available));
+    {
+      char *str;
+
+      str = TALER_amount_to_string (amount_available);
+      TALER_LOG_INFO ("expected available %s, actual %s\n",
+                      TALER_amount2s (&a),
+                      str);
+      GNUNET_free (str);
+    }
     if (0 != TALER_amount_cmp (amount_available, &a))
       TALER_TESTING_FAIL (tqs->is);
   }
@@ -567,9 +573,15 @@ tip_query_cb (void *cls,
   {
     GNUNET_assert (GNUNET_OK == TALER_string_to_amount
       (tqs->expected_amount_authorized, &a));
-    TALER_LOG_INFO ("expected authorized %s, actual %s\n",
-                    TALER_amount_to_string (&a),
-                    TALER_amount_to_string (amount_authorized));
+    {
+      char *str;
+
+      str = TALER_amount_to_string (amount_authorized);
+      TALER_LOG_INFO ("expected authorized %s, actual %s\n",
+                      TALER_amount2s (&a),
+                      str);
+      GNUNET_free (str);
+    }
     if (0 != TALER_amount_cmp (amount_authorized, &a))
       TALER_TESTING_FAIL (tqs->is);
   }
@@ -578,9 +590,14 @@ tip_query_cb (void *cls,
   {
     GNUNET_assert (GNUNET_OK == TALER_string_to_amount
       (tqs->expected_amount_picked_up, &a));
-    TALER_LOG_INFO ("expected picked_up %s, actual %s\n",
-                    TALER_amount_to_string (&a),
-                    TALER_amount_to_string (amount_picked_up));
+    {
+      char *str;
+      str = TALER_amount_to_string (amount_picked_up);
+      TALER_LOG_INFO ("expected picked_up %s, actual %s\n",
+                      TALER_amount2s (&a),
+                      str);
+      GNUNET_free (str);
+    }
     if (0 != TALER_amount_cmp (amount_picked_up, &a))
       TALER_TESTING_FAIL (tqs->is);
   }
@@ -910,7 +927,6 @@ tip_pickup_run (void *cls,
                 const struct TALER_TESTING_Command *cmd,
                 struct TALER_TESTING_Interpreter *is)
 {
-
   struct TipPickupState *tps = cls;
   unsigned int num_planchets;
   const struct TALER_TESTING_Command *replay_cmd;
@@ -1007,6 +1023,12 @@ tip_pickup_run (void *cls,
                                           planchets,
                                           &pickup_cb,
                                           tps);
+    for (unsigned int i=0;i<num_planchets;i++)
+    {
+      GNUNET_free (planchets[i].coin_ev);
+      planchets[i].coin_ev = NULL;
+      planchets[i].coin_ev_size = 0;
+    }
     GNUNET_assert (NULL != tps->tpo);
   }
 }
@@ -1028,7 +1050,13 @@ tip_pickup_cleanup (void *cls,
   GNUNET_free_non_null (tps->dks);
   GNUNET_free_non_null (tps->psa);
   GNUNET_free_non_null (tps->withdraws);
-  GNUNET_free_non_null (tps->sigs);
+  if (NULL != tps->sigs)
+  {
+    for (unsigned int i=0;i<tps->num_coins;i++)
+      if (NULL != tps->sigs[i].rsa_signature)
+        GNUNET_CRYPTO_rsa_signature_free (tps->sigs[i].rsa_signature);
+    GNUNET_free (tps->sigs);
+  }
 
   if (NULL != tps->tpo)
   {

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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