commit 4f097dd62fcf8f5e9ed8decd055aa3167d73c7e4
parent cb751157cccfbead1337416bc9e6357699ff7691
Author: Christian Blättler <blatc2@bfh.ch>
Date: Thu, 25 Apr 2024 18:21:36 +0200
fix set_token_family memory leaks
Diffstat:
2 files changed, 63 insertions(+), 34 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -681,7 +681,6 @@ clean_order (void *cls)
json_decref (oc->merge_inventory.products);
oc->merge_inventory.products = NULL;
}
- // TODO: Check if this is even correct
for (unsigned int i = 0; i<oc->parse_choices.choices_len; i++)
{
GNUNET_array_grow (oc->parse_choices.choices[i].inputs,
@@ -691,7 +690,25 @@ clean_order (void *cls)
oc->parse_choices.choices[i].outputs_len,
0);
}
- // TODO: Free token family public keys
+ GNUNET_array_grow (oc->parse_choices.choices,
+ oc->parse_choices.choices_len,
+ 0);
+ for (unsigned int i = 0; i<oc->parse_choices.token_families_len; i++)
+ {
+ GNUNET_free (oc->parse_choices.token_families[i].name);
+ GNUNET_free (oc->parse_choices.token_families[i].description);
+ json_decref (oc->parse_choices.token_families[i].description_i18n);
+ for (unsigned int j = 0; j<oc->parse_choices.token_families[i].keys_len; j++)
+ {
+ GNUNET_CRYPTO_blind_sign_pub_decref(oc->parse_choices.token_families[i].keys[j].pub.public_key);
+ }
+ GNUNET_array_grow (oc->parse_choices.token_families[i].keys,
+ oc->parse_choices.token_families[i].keys_len,
+ 0);
+ }
+ GNUNET_array_grow (oc->parse_choices.token_families,
+ oc->parse_choices.token_families_len,
+ 0);
GNUNET_array_grow (oc->parse_request.inventory_products,
oc->parse_request.inventory_products_length,
0);
@@ -1431,7 +1448,8 @@ set_token_family (struct OrderContext *oc,
struct TALER_MerchantContractTokenFamily *family = NULL;
enum GNUNET_DB_QueryStatus qs;
// TODO: make this configurable. This is the granularity of token
- // expiration dates.
+ // expiration dates. This should be stored in the
+ // database along the token family.
struct GNUNET_TIME_Relative precision = GNUNET_TIME_UNIT_MONTHS;
struct GNUNET_TIME_Timestamp min_valid_after;
struct GNUNET_TIME_Timestamp max_valid_after;
@@ -1476,7 +1494,6 @@ set_token_family (struct OrderContext *oc,
}
}
- family = GNUNET_new (struct TALER_MerchantContractTokenFamily);
qs = TMH_db->lookup_token_family_key (TMH_db->cls,
oc->hc->instance->settings.id,
@@ -1518,11 +1535,45 @@ set_token_family (struct OrderContext *oc,
return GNUNET_SYSERR;
}
+ /* slug is not needed */
+ GNUNET_free (key_details.token_family.slug);
+
+ if (NULL == family)
+ {
+ struct TALER_MerchantContractTokenFamily new_family = {
+ .slug = slug,
+ .name = key_details.token_family.name,
+ .description = key_details.token_family.description,
+ .description_i18n = key_details.token_family.description_i18n,
+ .keys = GNUNET_new (struct TALER_MerchantContractTokenFamilyKey),
+ .keys_len = 0,
+ };
+
+ switch (key_details.token_family.kind) {
+ case TALER_MERCHANTDB_TFK_Subscription:
+ new_family.kind = TALER_MCTK_SUBSCRIPTION;
+ new_family.critical = true;
+ // TODO: Set trusted domains
+ break;
+ case TALER_MERCHANTDB_TFK_Discount:
+ new_family.kind = TALER_MCTK_DISCOUNT;
+ new_family.critical = false;
+ // TODO: Set expected domains
+ break;
+ }
+
+ GNUNET_array_append (oc->parse_choices.token_families,
+ oc->parse_choices.token_families_len,
+ new_family);
+
+ family = &oc->parse_choices.token_families[oc->parse_choices.token_families_len - 1];
+ }
+
if (NULL == key_details.pub.public_key)
{
/* There is no matching key for this token family yet. */
/* We have to generate one. */
- /* If public key is invalid, private key must also be invalid */
+ /* If public key is NULL, private key must also be NULL */
GNUNET_assert (NULL == key_details.priv.private_key);
enum GNUNET_DB_QueryStatus iqs;
@@ -1603,34 +1654,10 @@ set_token_family (struct OrderContext *oc,
};
GNUNET_array_append (family->keys,
- family->keys_len,
- key);
+ family->keys_len,
+ key);
}
- family->slug = slug;
- family->name = key_details.token_family.name;
- family->description = key_details.token_family.description;
- family->description_i18n = key_details.token_family.description_i18n;
-
- GNUNET_free (key_details.token_family.slug);
-
- switch (key_details.token_family.kind) {
- case TALER_MERCHANTDB_TFK_Subscription:
- family->kind = TALER_MCTK_SUBSCRIPTION;
- family->critical = true;
- // TODO: Set trusted domains
- break;
- case TALER_MERCHANTDB_TFK_Discount:
- family->kind = TALER_MCTK_DISCOUNT;
- family->critical = false;
- // TODO: Set expected domains
- break;
- }
-
- GNUNET_array_append (oc->parse_choices.token_families,
- oc->parse_choices.token_families_len,
- *family);
-
return GNUNET_OK;
}
@@ -1858,11 +1885,11 @@ serialize_order (struct OrderContext *oc)
TALER_JSON_pack_amount ("amount",
&oc->parse_order.brutto),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_array_incref ("choices",
+ GNUNET_JSON_pack_array_steal ("choices",
choices)
),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_object_incref ("token_families",
+ GNUNET_JSON_pack_object_steal ("token_families",
token_families)
),
GNUNET_JSON_pack_allow_null (
@@ -2760,7 +2787,6 @@ merge_inventory (struct OrderContext *oc)
/* case listed to make compilers happy */
GNUNET_assert (0);
}
- json_decref (oc->merge_inventory.products);
reply_with_error (oc,
http_status,
ec,
diff --git a/src/backenddb/pg_lookup_token_family_key.c b/src/backenddb/pg_lookup_token_family_key.c
@@ -151,10 +151,13 @@ TMH_PG_lookup_token_family_key (void *cls,
details->token_family.kind = TALER_MERCHANTDB_TFK_Subscription;
else
{
+ GNUNET_free (kind);
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
}
}
+ GNUNET_free (kind);
+
return qs;
}
\ No newline at end of file