commit 48c7e1216fae9abb21c94d2c0ded328d05f1db01
parent 03117c758125946a29fe8c89a52c0fb70ed11213
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date: Tue, 24 Jun 2025 21:15:22 +0200
some cleaning of the memory leaks, clean up of the logic, tests passes
Diffstat:
2 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/src/lib/taler_merchant_pay_service.c b/src/lib/taler_merchant_pay_service.c
@@ -77,8 +77,8 @@ struct TALER_MERCHANT_OrderPayHandle
int choice_index;
/*Used for strcmp in the legacy we just keep it for this time*/
- struct TALER_Amount *amount;
- struct TALER_Amount *max_fee;
+ const struct TALER_Amount *amount;
+ const struct TALER_Amount *max_fee;
/* raw arrays as passed in via set_options(): */
struct {
@@ -399,6 +399,14 @@ handle_finished (void *cls,
}
oph->cb (oph->cb_cls,
&pr);
+
+ if (pr.details.ok.tokens)
+ {
+ GNUNET_free (pr.details.ok.tokens);
+ pr.details.ok.tokens = NULL;
+ pr.details.ok.num_tokens = 0;
+ }
+
TALER_MERCHANT_order_pay_cancel1 (oph);
}
@@ -422,10 +430,23 @@ TALER_MERCHANT_order_pay_cancel1 (struct TALER_MERCHANT_OrderPayHandle *ph)
{
if (ph->job)
GNUNET_CURL_job_cancel (ph->job);
+ ph->job = NULL;
+
TALER_curl_easy_post_finished (&ph->post_ctx);
- json_decref (ph->body);
- if (ph->tokens_evs) json_decref (ph->tokens_evs);
- if (ph->wallet_data) json_decref (ph->wallet_data);
+
+ if (ph->body)
+ json_decref (ph->body);
+ ph->body = NULL;
+
+ if (ph->wallet_data)
+ json_decref (ph->wallet_data);
+ ph->wallet_data = NULL;
+
+ if (ph->tokens_evs)
+ json_decref (ph->tokens_evs);
+ ph->tokens_evs = NULL;
+
+
GNUNET_free (ph->url);
GNUNET_free (ph->merchant_url);
GNUNET_free (ph->session_id);
@@ -556,7 +577,7 @@ TALER_MERCHANT_order_pay_set_options (struct TALER_MERCHANT_OrderPayHandle *ph,
case TALER_MERCHANT_OrderPayOptionType_COINS:
/* stash for later signing */
- GNUNET_assert (o->details.coins.num_coins > 0);
+ GNUNET_assert (o->details.coins.num_coins >= 0);
ph->coins.num_coins = o->details.coins.num_coins;
ph->coins.coins = o->details.coins.coins;
//ph->field_seen[o->ot] = true;
@@ -604,7 +625,7 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
/* all the old mandatory checks */
if (!ph->merchant_url || !ph->order_id)
return TALER_MERCHANT_OPOEC_MISSING_MANDATORY;
- if ( !(ph->coins.num_coins > 0) )
+ if ( !(ph->coins.num_coins >= 0) )
return TALER_MERCHANT_OPOEC_MISSING_MANDATORY;
if (GNUNET_YES !=
@@ -672,7 +693,8 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
pc.amount_with_fee = c->amount_with_fee;
pc.amount_without_fee = c->amount_without_fee;
pc.exchange_url = c->exchange_url;
- GNUNET_CRYPTO_eddsa_key_get_public(&c->coin_priv.eddsa_priv, &pc.coin_pub.eddsa_pub);
+ GNUNET_CRYPTO_eddsa_key_get_public(&c->coin_priv.eddsa_priv,
+ &pc.coin_pub.eddsa_pub);
/* JSON ------------------------------------------------------------ */
json_t *je = GNUNET_JSON_PACK(TALER_JSON_pack_amount("contribution", &pc.amount_with_fee),
@@ -700,9 +722,6 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
&total_amount,
&pc.amount_with_fee)) )
{
- /* integer overflow */
- GNUNET_break(0);
- json_decref(arr);
return TALER_MERCHANT_OPOEC_INVALID_VALUE;
}
}
@@ -723,6 +742,7 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
/* --- sign & pack input_tokens into used_tokens array in body --- */
if (ph->input_tokens.num_tokens > 0) {
struct TALER_MERCHANT_UsedToken ut[ph->input_tokens.num_tokens];
+ json_t *arr = json_array ();
for (unsigned i = 0; i < ph->input_tokens.num_tokens; i++) {
const struct TALER_MERCHANT_UseToken *in = &ph->input_tokens.tokens[i];
@@ -736,23 +756,19 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
t->ub_sig = in->ub_sig;
t->issue_pub = in->issue_pub;
- // Seems like we miss this function
- //
- //WHY can't we iliminate the second loop, makes no sense to keep it...
- }
+ GNUNET_CRYPTO_eddsa_key_get_public (&in->token_priv.private_key,
+ &t->token_pub.public_key);
- json_t *arr = json_array ();
- for (unsigned i = 0; i < ph->input_tokens.num_tokens; i++) {
- struct TALER_MERCHANT_UsedToken *t = &ut[i];
json_t *je = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("token_sig", &t->token_sig),
- GNUNET_JSON_pack_data_auto ("ub_sig", &t->ub_sig),
+ TALER_JSON_pack_token_issue_sig ("ub_sig", &t->ub_sig),
GNUNET_JSON_pack_data_auto ("h_issue",
&t->issue_pub.public_key->pub_key_hash),
- GNUNET_JSON_pack_data_auto ("issue_pub", &t->issue_pub)
+ GNUNET_JSON_pack_data_auto ("token_pub", &t->token_pub)
);
json_array_append_new (arr, je);
}
+
store_json_option (ph,
TALER_MERCHANT_OrderPayOptionType_INPUT_TOKENS,
GNUNET_JSON_PACK (
@@ -790,13 +806,11 @@ TALER_MERCHANT_order_pay_start (struct TALER_MERCHANT_OrderPayHandle *ph)
{
GNUNET_break (0);
curl_easy_cleanup (eh);
- json_decref (ph->body);
GNUNET_free (ph->url);
GNUNET_free (ph);
return TALER_MERCHANT_OPOEC_INVALID_VALUE;
}
- json_decref (ph->body);
ph->job = GNUNET_CURL_job_add2 (ph->ctx,
eh,
ph->post_ctx.headers,
diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c
@@ -1226,6 +1226,9 @@ pay_run (void *cls,
&h_proposal))
TALER_TESTING_FAIL (is);
ps->h_contract_terms = *h_proposal;
+
+ //old logic
+// {
// ps->oph = TALER_MERCHANT_order_pay (
// TALER_TESTING_interpreter_get_context (is),
// ps->merchant_url,
@@ -1250,11 +1253,11 @@ pay_run (void *cls,
// &pay_cb,
// ps);
//
-// GNUNET_array_grow (pay_coins,
-// npay_coins,
-// 0);
// if (NULL == ps->oph)
// TALER_TESTING_FAIL (is);
+//
+// }
+
// New logic of setting params
{
struct GNUNET_CURL_Context *ctx =
@@ -1308,6 +1311,17 @@ pay_run (void *cls,
TALER_TESTING_FAIL (is);
}
+ GNUNET_array_grow (pay_coins,
+ npay_coins,
+ 0);
+
+ GNUNET_array_grow(use_tokens,
+ len_use_tokens,
+ 0);
+
+ GNUNET_array_grow(output_tokens,
+ len_output_tokens,
+ 0);
}