gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 01/02: fix misc memory leaks
Date: Sun, 05 Mar 2017 18:18:31 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

commit b613bac566a695c4e122acfb4613f236bcb0d151
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Mar 5 18:17:42 2017 +0100

    fix misc memory leaks
---
 src/backend/taler-merchant-httpd.c          |  6 +-
 src/backend/taler-merchant-httpd_history.c  | 38 +++++++----
 src/backend/taler-merchant-httpd_pay.c      | 97 ++++++++++++++++-------------
 src/backend/taler-merchant-httpd_proposal.c | 19 +++---
 4 files changed, 89 insertions(+), 71 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 759719e..f13b891 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -254,6 +254,7 @@ hashmap_free (void *cls,
   struct MerchantInstance *mi = value;
 
   json_decref (mi->j_wire);
+  GNUNET_free (mi->id);
   GNUNET_free (mi->keyfile);
   GNUNET_free (mi);
   return GNUNET_YES;
@@ -501,11 +502,6 @@ instances_iterator_cb (void *cls,
                                       &mi->pubkey.eddsa_pub);
   GNUNET_free (pk);
 
-  /**
-   * FIXME: 'token' must NOT be freed, as it is handled by the
-   * gnunet_configuration facility. OTOH mi->id does need to be freed,
-   * because it is a duplicate.
-   */
   mi->id = GNUNET_strdup (token + 1);
   if (0 == strcmp ("default", mi->id))
     iic->default_instance = GNUNET_YES;
diff --git a/src/backend/taler-merchant-httpd_history.c 
b/src/backend/taler-merchant-httpd_history.c
index 73aab87..2e530e9 100644
--- a/src/backend/taler-merchant-httpd_history.c
+++ b/src/backend/taler-merchant-httpd_history.c
@@ -78,11 +78,11 @@ pd_cb (void *cls,
                 current,
                 start,
                 delta);
-    GNUNET_break (NULL != (entry = json_pack ("{s:s, s:O, s:s, s:s}",
+    GNUNET_break (NULL != (entry = json_pack ("{s:s, s:O, s:O, s:O}",
                                               "order_id", order_id,
                                               "amount", amount,
-                                              "timestamp", json_string_value 
(timestamp),
-                                              "instance", json_string_value 
(instance))));
+                                              "timestamp", timestamp,
+                                              "instance", instance)));
 
     GNUNET_break (0 == json_array_append_new (response,
                                               entry));
@@ -128,17 +128,22 @@ MH_handler_history (struct TMH_RequestHandler *rh,
   if (NULL != str)
   {
     if (1 != sscanf (str, "%llu", &seconds))
-    return TMH_RESPONSE_reply_arg_invalid (connection,
-                                          TALER_EC_PARAMETER_MALFORMED,
-                                           "date");
+    {
+      json_decref (response);
+      return TMH_RESPONSE_reply_arg_invalid (connection,
+                                             TALER_EC_PARAMETER_MALFORMED,
+                                             "date");
+    }
   }
 
   date.abs_value_us = seconds * 1000LL * 1000LL;
   if (date.abs_value_us / 1000LL / 1000LL != seconds)
+  {
+    json_decref (response);
     return TMH_RESPONSE_reply_bad_request (connection,
                                            TALER_EC_HISTORY_TIMESTAMP_OVERFLOW,
                                            "Timestamp overflowed");
-
+  }
 
 
   mi = TMH_lookup_instance ("default");
@@ -149,10 +154,12 @@ MH_handler_history (struct TMH_RequestHandler *rh,
     mi = TMH_lookup_instance (str);
 
   if (NULL == mi)
+  {
+    json_decref (response);
     return TMH_RESPONSE_reply_not_found (connection,
                                          TALER_EC_HISTORY_INSTANCE_UNKNOWN,
                                          "instance");
-
+  }
   start = 0;
   delta = 20;
 
@@ -163,9 +170,12 @@ MH_handler_history (struct TMH_RequestHandler *rh,
   {
     if ((1 != sscanf (str, "%d", &start)) ||
         start < 0)
+    {
+      json_decref (response);
       return TMH_RESPONSE_reply_arg_invalid (connection,
                                              TALER_EC_PARAMETER_MALFORMED,
                                              "start");
+    }
   }
 
   str = MHD_lookup_connection_value (connection,
@@ -191,17 +201,21 @@ MH_handler_history (struct TMH_RequestHandler *rh,
                                         response);
   current = 0;
   if (GNUNET_SYSERR == ret)
+  {
+    json_decref (response);
     return TMH_RESPONSE_reply_internal_error (connection,
                                              TALER_EC_HISTORY_DB_FETCH_ERROR,
                                              "db error to get history");
-
+  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "history data: %s\n",
               json_dumps (response, JSON_INDENT (1)));
 
-  return TMH_RESPONSE_reply_json (connection,
-                                  response,
-                                  MHD_HTTP_OK);
+  ret = TMH_RESPONSE_reply_json (connection,
+                                 response,
+                                 MHD_HTTP_OK);
+  json_decref (response);
+  return ret;
 }
 
 /* end of taler-merchant-httpd_history.c */
diff --git a/src/backend/taler-merchant-httpd_pay.c 
b/src/backend/taler-merchant-httpd_pay.c
index 2d86a12..91860ca 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -347,10 +347,11 @@ sign_success_response (struct PayContext *pc)
                             &mr.purpose,
                            &sig);
 
-  return TMH_RESPONSE_make_json_pack ("{s:O, s:s, s:o}",
-                                      "proposal_data", pc->proposal_data,
+  return TMH_RESPONSE_make_json_pack ("{s:O, s:o, s:o}",
+                                      "proposal_data",
+                                      pc->proposal_data,
                                       "sig",
-                                      json_string_value 
(GNUNET_JSON_from_data_auto (&sig)),
+                                      GNUNET_JSON_from_data_auto (&sig),
                                       "h_proposal_data",
                                       GNUNET_JSON_from_data 
(&pc->h_proposal_data,
                                                              sizeof (struct 
GNUNET_HashCode)));
@@ -451,9 +452,9 @@ deposit_cb (void *cls,
 
   if (0 != pc->pending)
     return; /* still more to do */
-
-
-  resume_pay_with_response (pc, MHD_HTTP_OK, sign_success_response (pc));
+  resume_pay_with_response (pc,
+                            MHD_HTTP_OK,
+                            sign_success_response (pc));
 }
 
 
@@ -914,7 +915,9 @@ transaction_double_check (void *cls,
  * @return #GNUNET_YES on success
  */
 static int
-parse_pay (struct MHD_Connection *connection, json_t *root, struct PayContext 
*pc)
+parse_pay (struct MHD_Connection *connection,
+           const json_t *root,
+           struct PayContext *pc)
 {
   json_t *coins;
   json_t *coin;
@@ -940,19 +943,17 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     GNUNET_break (0);
     return res;
   }
-
   res = db->find_proposal_data (db->cls,
                                 &pc->proposal_data,
                                 order_id,
                                 &merchant_pub);
-
-
   if (GNUNET_OK != res)
   {
-
-    if (MHD_YES != TMH_RESPONSE_reply_not_found (connection,
-                                                 
TALER_EC_PAY_DB_STORE_PAY_ERROR,
-                                                 "Proposal not found"))
+    GNUNET_JSON_parse_free (spec);
+    if (MHD_YES !=
+        TMH_RESPONSE_reply_not_found (connection,
+                                      TALER_EC_PAY_DB_STORE_PAY_ERROR,
+                                      "Proposal not found"))
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
@@ -960,12 +961,15 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     return GNUNET_NO;
   }
 
-
-  if (GNUNET_OK != TALER_JSON_hash (pc->proposal_data, &pc->h_proposal_data))
+  if (GNUNET_OK !=
+      TALER_JSON_hash (pc->proposal_data,
+                       &pc->h_proposal_data))
   {
-    if (MHD_YES != TMH_RESPONSE_reply_internal_error (connection,
-                                                      TALER_EC_NONE,
-                                                      "Can not hash proposal"))
+    GNUNET_JSON_parse_free (spec);
+    if (MHD_YES !=
+        TMH_RESPONSE_reply_internal_error (connection,
+                                           TALER_EC_NONE,
+                                           "Can not hash proposal"))
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
@@ -973,15 +977,18 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     return GNUNET_NO;
   }
 
-
-  merchant = json_object_get (pc->proposal_data, "merchant");
+  merchant = json_object_get (pc->proposal_data,
+                              "merchant");
   if (NULL == merchant)
   {
-    // invalid contract:
+    GNUNET_JSON_parse_free (spec);
+    /* invalid contract */
     GNUNET_break (0);
-    if (MHD_YES != TMH_RESPONSE_reply_internal_error (connection,
-                                                      TALER_EC_NONE,
-                                                      "No merchant field in 
contract"))
+    // FIXME: define proper EC for this!
+    if (MHD_YES !=
+        TMH_RESPONSE_reply_internal_error (connection,
+                                           TALER_EC_NONE,
+                                           "No merchant field in contract"))
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
@@ -994,6 +1001,7 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Not able to find the specified instance\n");
+    GNUNET_JSON_parse_free (spec);
     if (MHD_NO == TMH_RESPONSE_reply_not_found (connection,
                                                 TALER_EC_PAY_INSTANCE_UNKNOWN,
                                                 "Unknown instance given"))
@@ -1013,8 +1021,6 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Parsed JSON for /pay.\n");
 
-
-
   {
     struct GNUNET_JSON_Specification espec[] = {
       GNUNET_JSON_spec_absolute_time ("refund_deadline",
@@ -1040,7 +1046,9 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
       return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     }
 
-    pc->wire_transfer_deadline = GNUNET_TIME_absolute_add (pc->timestamp, 
wire_transfer_delay);
+    pc->wire_transfer_deadline
+      = GNUNET_TIME_absolute_add (pc->timestamp,
+                                  wire_transfer_delay);
 
     if (pc->wire_transfer_deadline.abs_value_us < 
pc->refund_deadline.abs_value_us)
     {
@@ -1052,7 +1060,8 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     }
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "parsed timestamps\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "parsed timestamps\n");
 
 
   pc->coins_cnt = json_array_size (coins);
@@ -1086,7 +1095,6 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     if (GNUNET_YES != res)
     {
       GNUNET_JSON_parse_free (spec);
-      json_decref (root);
       GNUNET_break (0);
       return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     }
@@ -1106,12 +1114,10 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
     dc->pc = pc;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "parsed coins\n");
-
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "parsed coins\n");
   pc->pending = pc->coins_cnt;
-
   GNUNET_JSON_parse_free (spec);
-
   return GNUNET_OK;
 }
 
@@ -1121,14 +1127,16 @@ parse_pay (struct MHD_Connection *connection, json_t 
*root, struct PayContext *p
  */
 static int
 handler_pay_json (struct MHD_Connection *connection,
-                  json_t *root,
+                  const json_t *root,
                   struct PayContext *pc)
 {
   int ret;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "about to parse '/pay' body\n");
-
-  ret = parse_pay (connection, root, pc);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "about to parse '/pay' body\n");
+  ret = parse_pay (connection,
+                   root,
+                   pc);
   if (GNUNET_OK != ret)
     return ret;
 
@@ -1229,7 +1237,7 @@ handler_pay_json (struct MHD_Connection *connection,
                                         &pc->mi->pubkey,
                                          &transaction_double_check,
                                          NULL))
-    GNUNET_break (0);                                         
+    GNUNET_break (0);
   }
 
   MHD_suspend_connection (connection);
@@ -1301,11 +1309,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
     res = MHD_queue_response (connection,
                              pc->response_code,
                              pc->response);
-    if (NULL != pc->response)
-    {
-      MHD_destroy_response (pc->response);
-      pc->response = NULL;
-    }
+    MHD_destroy_response (pc->response);
+    pc->response = NULL;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Queueing response (%u) for /pay (%s).\n",
                (unsigned int) pc->response_code,
@@ -1332,7 +1337,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
   if ((GNUNET_NO == res) || (NULL == root))
     return MHD_YES; /* the POST's body has to be further fetched */
 
-  res = handler_pay_json (connection, root, pc);
+  res = handler_pay_json (connection,
+                          root,
+                          pc);
   json_decref (root);
   if (GNUNET_SYSERR == res)
     return MHD_NO;
diff --git a/src/backend/taler-merchant-httpd_proposal.c 
b/src/backend/taler-merchant-httpd_proposal.c
index ac71653..09b221e 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -127,8 +127,9 @@ get_instance (struct json_t *json);
  * @param order to process
  * @return MHD result code
  */
-int
-proposal_put (struct MHD_Connection *connection, json_t *order)
+static int
+proposal_put (struct MHD_Connection *connection,
+              json_t *order)
 {
   int res;
   struct MerchantInstance *mi;
@@ -171,7 +172,7 @@ proposal_put (struct MHD_Connection *connection, json_t 
*order)
 
     off = strftime (buf, sizeof (buf), "%H:%M:%S", tm_info);
     snprintf (buf + off, sizeof (buf) - off,
-              "-%llX", 
+              "-%llX",
               (long long unsigned) GNUNET_CRYPTO_random_u64 
(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX));
     json_object_set (order, "order_id", json_string (buf));
   }
@@ -210,7 +211,7 @@ proposal_put (struct MHD_Connection *connection, json_t 
*order)
                                              TALER_EC_NONE,
                                              "Impossible to parse the order");
   }
-    
+
 
   /* check contract is well-formed */
   if (GNUNET_OK != check_products (products))
@@ -225,7 +226,7 @@ proposal_put (struct MHD_Connection *connection, json_t 
*order)
   if (NULL == mi)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Not able to find the specified instance\n"); 
+                "Not able to find the specified instance\n");
     return TMH_RESPONSE_reply_not_found (connection,
                                         TALER_EC_CONTRACT_INSTANCE_UNKNOWN,
                                         "Unknown instance given");
@@ -272,7 +273,7 @@ proposal_put (struct MHD_Connection *connection, json_t 
*order)
                                               TALER_EC_PROPOSAL_STORE_DB_ERROR,
                                               "db error: could not store this 
proposal's data into db");
   }
-  
+
 
   res = TMH_RESPONSE_reply_json_pack (connection,
                                       MHD_HTTP_OK,
@@ -396,7 +397,7 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
                                 order_id,
                                 &mi->pubkey);
   if (GNUNET_NO == res)
-    return TMH_RESPONSE_reply_not_found (connection, 
+    return TMH_RESPONSE_reply_not_found (connection,
                                          TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND,
                                          "unknown transaction id");
 
@@ -405,10 +406,10 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
                                               
TALER_EC_PROPOSAL_LOOKUP_DB_ERROR,
                                               "An error occurred while 
retrieving proposal data from db");
 
-  
+
   return TMH_RESPONSE_reply_json (connection,
                                   proposal_data,
-                                  MHD_HTTP_OK); 
+                                  MHD_HTTP_OK);
 
 
 }

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



reply via email to

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