summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-06-04 22:33:54 +0200
committerChristian Grothoff <christian@grothoff.org>2017-06-04 22:33:54 +0200
commitf1395b9cd50df28853cd138557b41ddd79b4ecd3 (patch)
tree9b938a34659d3acece52e430fc8c666dbedf5e5f
parentd274ac3e73dd30de260e1c36c4bee76b935f28d3 (diff)
downloadmerchant-f1395b9cd50df28853cd138557b41ddd79b4ecd3.tar.gz
merchant-f1395b9cd50df28853cd138557b41ddd79b4ecd3.tar.bz2
merchant-f1395b9cd50df28853cd138557b41ddd79b4ecd3.zip
fix misc leaks
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.c7
-rw-r--r--src/backend/taler-merchant-httpd_proposal.c23
-rw-r--r--src/backend/taler-merchant-httpd_track-transfer.c68
-rw-r--r--src/lib/merchant_api_pay.c1
-rw-r--r--src/lib/merchant_api_proposal.c63
-rw-r--r--src/lib/test_merchant_api.c36
6 files changed, 118 insertions, 80 deletions
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c
index f8e67054..3883d57f 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -937,9 +937,16 @@ TMH_EXCHANGES_done ()
exchange);
while (NULL != (f = exchange->wire_fees_head))
{
+ struct TALER_EXCHANGE_WireAggregateFees *af;
+
GNUNET_CONTAINER_DLL_remove (exchange->wire_fees_head,
exchange->wire_fees_tail,
f);
+ while (NULL != (af = f->af))
+ {
+ f->af = af->next;
+ GNUNET_free (af);
+ }
GNUNET_free (f->wire_method);
GNUNET_free (f);
}
diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c
index 85a43c0a..7a1cabbb 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -160,7 +160,8 @@ proposal_put (struct MHD_Connection *connection,
/* Add order_id if it doesn't exist. */
- if (NULL == json_string_value (json_object_get (order, "order_id")))
+ if (NULL == json_string_value (json_object_get (order,
+ "order_id")))
{
char buf[256];
time_t timer;
@@ -183,7 +184,8 @@ proposal_put (struct MHD_Connection *connection,
json_string (buf));
}
- if (NULL == json_object_get (order, "timestamp"))
+ if (NULL == json_object_get (order,
+ "timestamp"))
{
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
@@ -233,7 +235,9 @@ proposal_put (struct MHD_Connection *connection,
}
/* extract fields we need to sign separately */
- res = TMH_PARSE_json_data (connection, order, spec);
+ res = TMH_PARSE_json_data (connection,
+ order,
+ spec);
if (GNUNET_NO == res)
{
return MHD_YES;
@@ -245,7 +249,6 @@ proposal_put (struct MHD_Connection *connection,
"Impossible to parse the order");
}
-
/* check contract is well-formed */
if (GNUNET_OK != check_products (products))
{
@@ -260,6 +263,7 @@ proposal_put (struct MHD_Connection *connection,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Not able to find the specified instance\n");
+ GNUNET_JSON_parse_free (spec);
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_CONTRACT_INSTANCE_UNKNOWN,
"Unknown instance given");
@@ -343,6 +347,8 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
{
int res;
struct TMH_JsonParseContext *ctx;
+ json_t *root;
+ json_t *order;
if (NULL == *connection_cls)
{
@@ -355,8 +361,6 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
ctx = *connection_cls;
}
- json_t *root;
-
res = TMH_PARSE_post_json (connection,
&ctx->json_parse_context,
upload_data,
@@ -368,8 +372,8 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
if ((GNUNET_NO == res) || (NULL == root))
return MHD_YES;
- json_t *order = json_object_get (root, "order");
-
+ order = json_object_get (root,
+ "order");
if (NULL == order)
{
res = TMH_RESPONSE_reply_arg_missing (connection,
@@ -378,7 +382,8 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
}
else
{
- res = proposal_put (connection, order);
+ res = proposal_put (connection,
+ order);
}
json_decref (root);
return res;
diff --git a/src/backend/taler-merchant-httpd_track-transfer.c b/src/backend/taler-merchant-httpd_track-transfer.c
index 168fdcb0..a0dadabe 100644
--- a/src/backend/taler-merchant-httpd_track-transfer.c
+++ b/src/backend/taler-merchant-httpd_track-transfer.c
@@ -108,6 +108,11 @@ struct TrackTransferContext
const json_t *original_response;
/**
+ * Modified response to return to the frontend.
+ */
+ json_t *deposits_response;
+
+ /**
* Which transaction detail are we currently looking at?
*/
unsigned int current_offset;
@@ -130,6 +135,7 @@ struct TrackTransferContext
* individual deposits for each h_contract_terms.
*/
struct Entry {
+
/**
* Sum accumulator for deposited value.
*/
@@ -140,12 +146,8 @@ struct Entry {
*/
struct TALER_Amount deposit_fee;
- };
+};
-/**
- * Modified response to return to the frontend.
- */
-static json_t *deposits_response;
/**
* Free the @a rctx.
@@ -184,8 +186,8 @@ free_transfer_track_context (struct TrackTransferContext *rctx)
* @param cls closure, NULL
* @param key current key
* @param value a `struct MerchantInstance`
- * @return GNUNET_YES if the iteration should continue,
- * GNUNET_NO otherwise.
+ * @return #GNUNET_YES if the iteration should continue,
+ * #GNUNET_NO otherwise.
*/
static int
hashmap_free (void *cls,
@@ -206,10 +208,10 @@ hashmap_free (void *cls,
* @param cls closure
* @param key map's current key
* @param map's current value
- * @return GNUNET_YES if iteration is to be continued,
- * GNUNET_NO otherwise.
+ * @return #GNUNET_YES if iteration is to be continued,
+ * #GNUNET_NO otherwise.
*/
-int
+static int
build_deposits_response (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -220,31 +222,35 @@ build_deposits_response (void *cls,
json_t *contract_terms;
json_t *order_id;
- if (GNUNET_OK != db->find_contract_terms_from_hash (db->cls,
- &contract_terms,
- key,
- &rctx->mi->pubkey))
+ if (GNUNET_OK !=
+ db->find_contract_terms_from_hash (db->cls,
+ &contract_terms,
+ key,
+ &rctx->mi->pubkey))
{
GNUNET_break_op (0);
return GNUNET_NO;
}
- order_id = json_object_get (contract_terms, "order_id");
+ order_id = json_object_get (contract_terms,
+ "order_id");
if (NULL == order_id)
{
GNUNET_break_op (0);
+ json_decref (contract_terms);
return GNUNET_NO;
}
- element = json_pack ("{s:s, s:o, s:o}",
- "order_id", json_string_value (order_id),
+ element = json_pack ("{s:O, s:o, s:o}",
+ "order_id", order_id,
"deposit_value", TALER_JSON_from_amount (&entry->deposit_value),
"deposit_fee", TALER_JSON_from_amount (&entry->deposit_fee));
+ json_decref (contract_terms);
if (NULL == element)
{
GNUNET_break_op (0);
return GNUNET_NO;
}
- json_array_append_new (deposits_response,
+ json_array_append_new (rctx->deposits_response,
element);
return GNUNET_YES;
}
@@ -302,12 +308,14 @@ transform_response (const json_t *result,
&h_key)))
{
/* The map already knows this h_contract_terms*/
- if ((GNUNET_SYSERR == TALER_amount_add (&current_entry->deposit_value,
- &current_entry->deposit_value,
- &iter_value)) ||
- (GNUNET_SYSERR == TALER_amount_add (&current_entry->deposit_fee,
- &current_entry->deposit_fee,
- &iter_fee)))
+ if ( (GNUNET_SYSERR ==
+ TALER_amount_add (&current_entry->deposit_value,
+ &current_entry->deposit_value,
+ &iter_value)) ||
+ (GNUNET_SYSERR ==
+ TALER_amount_add (&current_entry->deposit_fee,
+ &current_entry->deposit_fee,
+ &iter_fee)) )
{
GNUNET_JSON_parse_free (spec);
goto cleanup;
@@ -332,11 +340,12 @@ transform_response (const json_t *result,
}
GNUNET_JSON_parse_free (spec);
}
- deposits_response = json_array ();
+ rctx->deposits_response = json_array ();
- if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_iterate (map,
- build_deposits_response,
- rctx))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multihashmap_iterate (map,
+ &build_deposits_response,
+ rctx))
goto cleanup;
result_mod = json_copy ((struct json_t *) result);
@@ -344,7 +353,8 @@ transform_response (const json_t *result,
"deposits");
json_object_set_new (result_mod,
"deposits_sums",
- deposits_response);
+ rctx->deposits_response);
+ rctx->deposits_response = NULL;
cleanup:
GNUNET_CONTAINER_multihashmap_iterate (map,
&hashmap_free,
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 9422e07e..aa875bc4 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -243,6 +243,7 @@ handle_pay_finished (void *cls,
response_code,
TALER_JSON_get_error_code (json),
json);
+ TALER_MERCHANT_pay_cancel (ph);
}
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index c200ce5b..7eddeaf7 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -127,9 +127,9 @@ handle_proposal_finished (void *cls,
hashp = NULL;
switch (response_code)
{
- case 0:
- break;
- case MHD_HTTP_OK:
+ case 0:
+ break;
+ case MHD_HTTP_OK:
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("data", &contract_terms),
@@ -150,33 +150,33 @@ handle_proposal_finished (void *cls,
hashp = &hash;
sigp = &sig;
}
- break;
- case MHD_HTTP_BAD_REQUEST:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the merchant is buggy
(or API version conflict); just pass JSON reply to the application */
- break;
- case MHD_HTTP_FORBIDDEN:
- break;
- case MHD_HTTP_UNAUTHORIZED:
- /* Nothing really to verify, merchant says one of the signatures is
- invalid; as we checked them, this should never happen, we
- should pass the JSON reply to the application */
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- break;
- default:
- /* unexpected response code */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* Nothing really to verify, merchant says one of the signatures is
+ invalid; as we checked them, this should never happen, we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u\n",
+ (unsigned int) response_code);
+ GNUNET_break (0);
+ response_code = 0;
}
po->cb (po->cb_cls,
response_code,
@@ -187,6 +187,7 @@ handle_proposal_finished (void *cls,
hashp);
if (NULL != contract_terms)
json_decref (contract_terms);
+ TALER_MERCHANT_proposal_cancel (po);
}
@@ -255,6 +256,7 @@ TALER_MERCHANT_order_put (struct GNUNET_CURL_Context *ctx,
return po;
}
+
/**
* Function called when we're done processing the GET /proposal request.
*
@@ -276,8 +278,10 @@ handle_proposal_lookup_finished (void *cls,
plo->cb (plo->cb_cls,
response_code,
json);
+ TALER_MERCHANT_proposal_lookup_cancel (plo);
}
+
/**
* Calls the GET /proposal API at the backend. That is,
* retrieve a proposal data by providing its transaction id.
@@ -329,9 +333,9 @@ TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
return NULL;
}
return plo;
-
}
+
/**
* Cancel a PUT /proposal request. This function cannot be used
* on a request handle if a response is already served for it.
@@ -351,6 +355,7 @@ TALER_MERCHANT_proposal_cancel (struct TALER_MERCHANT_ProposalOperation *po)
GNUNET_free (po);
}
+
/**
* Cancel a GET /proposal request.
*
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 6d0f6138..0871d214 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -1243,6 +1243,7 @@ track_transfer_cb (void *cls,
next_command (is);
}
+
/**
* Callback for GET /proposal issued at backend. Just check
* whether response code is as expected.
@@ -1259,13 +1260,12 @@ proposal_lookup_cb (void *cls,
struct Command *cmd = &is->commands[is->ip];
cmd->details.proposal_lookup.plo = NULL;
-
if (cmd->expected_response_code != http_status)
fail (is);
-
next_command (is);
}
+
/**
* Function called with detailed wire transfer data.
*
@@ -1402,7 +1402,7 @@ interpreter_run (void *cls)
instance_idx++;
instance = instances[instance_idx];
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Switching instance: '%s'\n",
+ "Switching instance: `%s'\n",
instance);
is->task = GNUNET_SCHEDULER_add_now (interpreter_run,
@@ -1598,14 +1598,15 @@ interpreter_run (void *cls)
&error);
if (NULL != instance)
{
-
json_t *merchant;
merchant = json_object ();
json_object_set_new (merchant,
"instance",
json_string (instance));
- json_object_set (order, "merchant", merchant);
+ json_object_set_new (order,
+ "merchant",
+ merchant);
}
if (NULL == order)
{
@@ -2058,6 +2059,8 @@ do_shutdown (void *cls)
is->task = NULL;
}
GNUNET_free (is);
+ for (unsigned int i=0;i<ninstances;i++)
+ GNUNET_free (instances[i]);
GNUNET_free_non_null (instances);
if (NULL != exchange)
{
@@ -2429,16 +2432,23 @@ main (int argc,
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_load (cfg,
"test_merchant_api.conf"));
- GNUNET_break (GNUNET_CONFIGURATION_get_value_string (cfg,
- "merchant",
- "INSTANCES",
- &_instances));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "merchant",
+ "INSTANCES",
+ &_instances));
+ fprintf (stderr,
+ "Found instances `%s'\n",
+ _instances);
GNUNET_break (NULL != (token = strtok (_instances, " ")));
- GNUNET_array_append (instances, ninstances, token);
-
+ GNUNET_array_append (instances,
+ ninstances,
+ GNUNET_strdup (token));
while (NULL != (token = strtok (NULL, " ")))
- GNUNET_array_append(instances, ninstances, token);
-
+ GNUNET_array_append (instances,
+ ninstances,
+ GNUNET_strdup (token));
+ GNUNET_free (_instances);
instance = instances[instance_idx];
db = TALER_MERCHANTDB_plugin_load (cfg);
if (NULL == db)