merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit c38fbc4b7b2b09042a15cb95d471153f4dec5e72
parent 8954e10862422642c52ba4a17a133a86d9afdaed
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 25 Oct 2025 21:18:17 +0200

fix leak (#10505)

Diffstat:
Msrc/include/taler_merchant_util.h | 12+++++++++---
Msrc/util/contract_parse.c | 24+++++++++++++++++++++---
Msrc/util/contract_serialize.c | 30++++++++++++++----------------
3 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/src/include/taler_merchant_util.h b/src/include/taler_merchant_util.h @@ -346,6 +346,7 @@ struct TALER_MERCHANT_ContractOutput union { +#if FUTURE /** * Coin-based output. */ @@ -358,11 +359,14 @@ struct TALER_MERCHANT_ContractOutput /** * Base URL of the exchange that will issue the coins. + * + * NOTE: Once implemented, check if we need to allocate this here or if + * we again reference the JSON as we do in other places. */ char *exchange_url; } coin; - +#endif /** * DONAU-receipt output. */ @@ -376,9 +380,9 @@ struct TALER_MERCHANT_ContractOutput /** * Base URLs of the donation authorities that will issue the tax receipt. */ - const char **donau_urls; + char **donau_urls; - /* + /** * Length of the @e donau_urls array. */ unsigned int donau_urls_len; @@ -392,6 +396,8 @@ struct TALER_MERCHANT_ContractOutput { /** * Slug of the token family to be issued. + * Note: this is a pointer into the JSON of the + * respective contract/request and not owned here. */ const char *token_family_slug; diff --git a/src/util/contract_parse.c b/src/util/contract_parse.c @@ -323,9 +323,8 @@ TALER_MERCHANT_parse_choice_output ( GNUNET_break_op (0); return GNUNET_SYSERR; } - output->details.donation_receipt.donau_urls[i] = - json_string_value (jurl); + GNUNET_strdup (json_string_value (jurl)); } return GNUNET_OK; @@ -527,7 +526,26 @@ contract_choice_free ( { struct TALER_MERCHANT_ContractOutput *output = &choice->outputs[i]; - GNUNET_free (output->details.coin.exchange_url); + switch (output->type) + { + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_INVALID: + GNUNET_break (0); + break; + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN: + break; + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: + for (unsigned int j = 0; + j<output->details.donation_receipt.donau_urls_len; + j++) + GNUNET_free (output->details.donation_receipt.donau_urls[j]); + GNUNET_free (output->details.donation_receipt.donau_urls); + break; +#if FUTURE + case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_COIN: + GNUNET_free (output->details.coin.exchange_url); + break; +#endif + } } GNUNET_free (choice->description); if (NULL != choice->description_i18n) diff --git a/src/util/contract_serialize.c b/src/util/contract_serialize.c @@ -126,15 +126,14 @@ json_from_contract_output ( donau_urls = json_array (); GNUNET_assert (NULL != donau_urls); - for (unsigned i = 0; i < output->details.donation_receipt.donau_urls_len; i++) GNUNET_assert (0 == - json_array_append_new (donau_urls, - json_string (output->details. - donation_receipt. - donau_urls[i]))); + json_array_append_new ( + donau_urls, + json_string ( + output->details.donation_receipt.donau_urls[i]))); return GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("type", @@ -146,9 +145,8 @@ json_from_contract_output ( &output->details.donation_receipt.amount))); } } - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "unsupported contract output type %d", + "Unsupported contract output type %d", output->type); GNUNET_assert (0); return NULL; @@ -170,7 +168,6 @@ TALER_MERCHANT_json_from_contract_choice ( json_array_append_new (inputs, json_from_contract_input ( &choice->inputs[i]))); - outputs = json_array (); GNUNET_assert (NULL != outputs); for (unsigned int i = 0; i < choice->outputs_len; i++) @@ -190,12 +187,13 @@ TALER_MERCHANT_json_from_contract_choice ( choice->description_i18n)), (order) ? GNUNET_JSON_pack_allow_null ( - TALER_JSON_pack_amount ("max_fee", - /* workaround for nullable amount */ - (GNUNET_OK == - TALER_amount_is_valid (&choice->max_fee)) - ? &choice->max_fee - : NULL)) + TALER_JSON_pack_amount ( + "max_fee", + /* workaround for nullable amount */ + (GNUNET_OK == + TALER_amount_is_valid (&choice->max_fee)) + ? &choice->max_fee + : NULL)) : TALER_JSON_pack_amount ("max_fee", &choice->max_fee), (order) @@ -208,8 +206,8 @@ TALER_MERCHANT_json_from_contract_choice ( ? GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_array_steal ("outputs", outputs)) - : GNUNET_JSON_pack_array_steal ("outputs", - outputs)); + : GNUNET_JSON_pack_array_steal ("outputs", + outputs)); }