commit 9831b7a7046a1a9b016b48a700d019f8f386639f
parent a1b7ba46bc4f809048533beaa2e9981fccae797f
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 20 May 2026 12:21:41 +0200
-fix leaks
Diffstat:
4 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_post-templates-TEMPLATE_ID.c b/src/backend/taler-merchant-httpd_post-templates-TEMPLATE_ID.c
@@ -290,9 +290,9 @@ struct UseContext
* @param[in] items item array to free
*/
static void
-cleanup_inventory_items (unsigned int items_len,
- struct InventoryTemplateItemContext items[static
- items_len])
+cleanup_inventory_items (
+ unsigned int items_len,
+ struct InventoryTemplateItemContext items[static items_len])
{
for (unsigned int i = 0; i < items_len; i++)
{
@@ -320,6 +320,7 @@ cleanup_use_context (void *cls)
uc->parse_request.inventory.items)
cleanup_inventory_items (uc->parse_request.inventory.items_len,
uc->parse_request.inventory.items);
+ TALER_MERCHANT_template_contract_free (&uc->template_contract);
GNUNET_free (uc->compute_price.totals);
uc->compute_price.totals_len = 0;
json_decref (uc->compute_price.choices);
diff --git a/src/include/taler/taler_merchant_util.h b/src/include/taler/taler_merchant_util.h
@@ -405,6 +405,18 @@ TALER_MERCHANT_template_contract_parse (
struct TALER_MERCHANT_TemplateContract *out,
const char **error_name);
+
+/**
+ * Release memory from template contract @a tc.
+ * Does not free @a tc itself.
+ *
+ * @param[in] tc contract to free
+ */
+void
+TALER_MERCHANT_template_contract_free (
+ struct TALER_MERCHANT_TemplateContract *tc);
+
+
/**
* Check if @a template_contract is valid.
*
diff --git a/src/util/contract_parse.c b/src/util/contract_parse.c
@@ -368,6 +368,8 @@ parse_choices (
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ *choices = NULL;
+ *choices_len = 0;
GNUNET_array_grow (*choices,
*choices_len,
json_array_size (root));
diff --git a/src/util/template_parse.c b/src/util/template_parse.c
@@ -336,13 +336,42 @@ TALER_MERCHANT_template_contract_parse (
}
+void
+TALER_MERCHANT_template_contract_free (
+ struct TALER_MERCHANT_TemplateContract *tc)
+{
+ switch (tc->type)
+ {
+ case TALER_MERCHANT_TEMPLATE_TYPE_FIXED_ORDER:
+ return;
+ case TALER_MERCHANT_TEMPLATE_TYPE_INVENTORY_CART:
+ return;
+ case TALER_MERCHANT_TEMPLATE_TYPE_PAIVANA:
+ for (unsigned int i = 0; i<tc->details.paivana.choices_len; i++)
+ TALER_MERCHANT_contract_choice_free (&tc->details.paivana.choices[i]);
+ GNUNET_array_grow (tc->details.paivana.choices,
+ tc->details.paivana.choices_len,
+ 0);
+ return;
+ case TALER_MERCHANT_TEMPLATE_TYPE_INVALID:
+ return;
+ }
+}
+
+
bool
TALER_MERCHANT_template_contract_valid (const json_t *template_contract)
{
struct TALER_MERCHANT_TemplateContract tmp;
-
- return (GNUNET_OK ==
- TALER_MERCHANT_template_contract_parse (template_contract,
- &tmp,
- NULL));
+ bool ret;
+
+ memset (&tmp,
+ 0,
+ sizeof (tmp));
+ ret = (GNUNET_OK ==
+ TALER_MERCHANT_template_contract_parse (template_contract,
+ &tmp,
+ NULL));
+ TALER_MERCHANT_template_contract_free (&tmp);
+ return ret;
}