commit 5160c318da5ad53ceb3542e2b1d2ec79b9954d43
parent bd6574c150fe93cf0c7f3720f20df7b8ebb57944
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 9 May 2025 23:38:02 +0200
fix misc. memory leaks
Diffstat:
13 files changed, 103 insertions(+), 37 deletions(-)
diff --git a/src/backend/taler-merchant-exchangekeyupdate.c b/src/backend/taler-merchant-exchangekeyupdate.c
@@ -529,6 +529,7 @@ cert_cb (
e->exchange_url,
keys->currency,
e->currency);
+ TALER_EXCHANGE_keys_decref (keys);
break;
}
if (0 != GNUNET_memcmp (&keys->master_pub,
@@ -537,6 +538,7 @@ cert_cb (
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Master public key in %skeys response does not match. Ignoring response.\n",
e->exchange_url);
+ TALER_EXCHANGE_keys_decref (keys);
break;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -548,9 +550,10 @@ cert_cb (
first_retry))
{
GNUNET_break (0);
+ TALER_EXCHANGE_keys_decref (keys);
break;
}
- e->keys = TALER_EXCHANGE_keys_incref (keys);
+ e->keys = keys;
/* Reset back-off */
e->retry_delay = EXCHANGE_MAXFREQ;
/* limit retry */
@@ -566,6 +569,7 @@ cert_cb (
end_inquiry ();
return;
default:
+ GNUNET_break (NULL == keys);
break;
}
/* Try again (soon-ish) */
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -302,11 +302,8 @@ suspend_god (struct GetOrderData *god)
if (NULL != god->contract_terms_json)
{
json_decref (god->contract_terms_json);
- god->contract_terms->fulfillment_url = NULL;
god->contract_terms_json = NULL;
god->contract_parsed = false;
- god->contract_terms->merchant_base_url = NULL;
- god->contract_terms->public_reorder_url = NULL;
}
if (NULL != god->contract_terms)
{
@@ -731,6 +728,7 @@ phase_lookup_terms (struct GetOrderData *god)
static void
phase_parse_contract (struct GetOrderData *god)
{
+ GNUNET_break (NULL == god->contract_terms);
god->contract_terms = TALER_MERCHANT_contract_parse (
god->contract_terms_json,
true);
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -3784,6 +3784,13 @@ pay_context_cleanup (void *cls)
GNUNET_free (dc->exchange_url);
}
GNUNET_free (pc->parse_pay.dc);
+ for (unsigned int i = 0; i<pc->parse_pay.tokens_cnt; i++)
+ {
+ struct TokenUseConfirmation *tuc = &pc->parse_pay.tokens[i];
+
+ TALER_token_issue_sig_free (&tuc->unblinded_sig);
+ }
+ GNUNET_free (pc->parse_pay.tokens);
for (unsigned int i = 0; i<pc->parse_pay.num_exchanges; i++)
{
struct ExchangeGroup *eg = pc->parse_pay.egs[i];
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c b/src/backend/taler-merchant-httpd_post-using-templates.c
@@ -46,6 +46,10 @@ struct UseContext
*/
struct TALER_MERCHANTDB_TemplateDetails etp;
+ /**
+ * True once @e etp was initialized.
+ */
+ bool have_etp;
};
@@ -117,6 +121,7 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh,
}
}
+ if (! uc->have_etp)
{
enum GNUNET_DB_QueryStatus qs;
@@ -154,10 +159,10 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh,
template_id);
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
/* all good */
+ uc->have_etp = true;
break;
} /* End of the switch */
}
-
{
/* template */
const char *tsummary = NULL;
@@ -295,7 +300,7 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh,
uc->ihc.request_body = fake_body;
return TMH_private_post_orders (
- NULL, /* not even used */
+ NULL, /* not even used */
connection,
&uc->ihc);
}
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -474,6 +474,16 @@ static void
gorc_cleanup (void *cls)
{
struct GetOrderRequestContext *gorc = cls;
+ struct TransferQuery *tq;
+
+ while (NULL != (tq = gorc->tq_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (gorc->tq_head,
+ gorc->tq_tail,
+ tq);
+ GNUNET_free (tq->exchange_url);
+ GNUNET_free (tq);
+ }
if (NULL != gorc->contract_terms_json)
json_decref (gorc->contract_terms_json);
@@ -937,6 +947,7 @@ phase_check_repurchase (struct GetOrderRequestContext *gorc)
gorc->contract_terms->summary),
GNUNET_JSON_pack_timestamp ("creation_time",
gorc->contract_terms->timestamp));
+ GNUNET_free (order_status_url);
GNUNET_free (taler_pay_uri);
GNUNET_free (already_paid_order_id);
phase_end (gorc,
@@ -1082,25 +1093,27 @@ process_refunds_cb (
NULL != tq;
tq = tq->next)
{
- if (0 ==
+ if (0 !=
+ strcmp (exchange_url,
+ tq->exchange_url))
+ continue;
+ if (0 !=
GNUNET_memcmp (&tq->coin_pub,
coin_pub))
+ continue;
+ if (GNUNET_OK !=
+ TALER_amount_cmp_currency (
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee))
{
- if (GNUNET_OK !=
- TALER_amount_cmp_currency (
- &gorc->deposit_fees_total,
- &tq->deposit_fee))
- {
- gorc->refund_currency_mismatch = true;
- return;
- }
-
- GNUNET_assert (
- 0 <=
- TALER_amount_subtract (&gorc->deposit_fees_total,
- &gorc->deposit_fees_total,
- &tq->deposit_fee));
+ gorc->refund_currency_mismatch = true;
+ return;
}
+ GNUNET_assert (
+ 0 <=
+ TALER_amount_subtract (&gorc->deposit_fees_total,
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee));
}
if (GNUNET_OK !=
TALER_amount_cmp_currency (
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -78,7 +78,7 @@
* refuses a forced download.
*/
#define MAX_KEYS_WAIT \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2500)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2500)
/**
* Generate the base URL for the given merchant instance.
@@ -3784,6 +3784,9 @@ parse_request (struct OrderContext *oc)
struct TALER_MERCHANTDB_OtpDeviceDetails td;
enum GNUNET_DB_QueryStatus qs;
+ memset (&td,
+ 0,
+ sizeof (td));
qs = TMH_db->select_otp (TMH_db->cls,
oc->hc->instance->settings.id,
otp_id,
@@ -3815,6 +3818,7 @@ parse_request (struct OrderContext *oc)
}
oc->parse_request.pos_key = td.otp_key;
oc->parse_request.pos_algorithm = td.otp_algorithm;
+ GNUNET_free (td.otp_description);
}
if (create_token)
{
diff --git a/src/backend/taler-merchant-kyccheck.c b/src/backend/taler-merchant-kyccheck.c
@@ -1369,6 +1369,7 @@ shutdown_task (void *cls)
a_tail,
a);
GNUNET_free (a->merchant_account_uri.full_payto);
+ GNUNET_free (a->instance_id);
GNUNET_free (a);
}
if (NULL != eh_accounts)
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
@@ -75,7 +75,7 @@ libtalermerchantdb_la_LIBADD = \
libtalermerchantdb_la_LDFLAGS = \
$(POSTGRESQL_LDFLAGS) \
- -version-info 4:0:2 \
+ -version-info 4:1:2 \
-no-undefined
libtaler_plugin_merchantdb_postgres_la_SOURCES = \
diff --git a/src/backenddb/merchantdb_helper.c b/src/backenddb/merchantdb_helper.c
@@ -30,10 +30,13 @@ TALER_MERCHANTDB_product_details_free (
{
GNUNET_free (pd->description);
json_decref (pd->description_i18n);
+ pd->description_i18n = NULL;
GNUNET_free (pd->unit);
json_decref (pd->taxes);
+ pd->taxes = NULL;
GNUNET_free (pd->image);
json_decref (pd->address);
+ pd->address = NULL;
}
@@ -44,7 +47,9 @@ TALER_MERCHANTDB_template_details_free (
GNUNET_free (tp->template_description);
GNUNET_free (tp->otp_id);
json_decref (tp->editable_defaults);
+ tp->editable_defaults = NULL;
json_decref (tp->template_contract);
+ tp->template_contract = NULL;
}
@@ -79,7 +84,9 @@ TALER_MERCHANTDB_token_family_details_free (
GNUNET_free (tf->name);
GNUNET_free (tf->description);
json_decref (tf->description_i18n);
+ tf->description_i18n = NULL;
json_decref (tf->extra_data);
+ tf->extra_data = NULL;
GNUNET_free (tf->cipher_spec);
}
@@ -90,6 +97,7 @@ TALER_MERCHANTDB_category_details_free (
{
GNUNET_free (cd->category_name);
json_decref (cd->category_name_i18n);
+ cd->category_name_i18n = NULL;
}
diff --git a/src/backenddb/pg_lookup_product.c b/src/backenddb/pg_lookup_product.c
@@ -25,6 +25,7 @@
#include "pg_lookup_product.h"
#include "pg_helper.h"
+
enum GNUNET_DB_QueryStatus
TMH_PG_lookup_product (void *cls,
const char *instance_id,
@@ -83,17 +84,24 @@ TMH_PG_lookup_product (void *cls,
}
else
{
+ char *my_description = NULL;
+ json_t *my_description_i18n = NULL;
+ char *my_unit = NULL;
+ char *my_image = NULL;
+ json_t *my_address = NULL;
+ json_t *my_taxes = NULL;
+ uint64_t *my_categories = NULL;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_string ("description",
- &pd->description),
+ &my_description),
TALER_PQ_result_spec_json ("description_i18n",
- &pd->description_i18n),
+ &my_description_i18n),
GNUNET_PQ_result_spec_string ("unit",
- &pd->unit),
+ &my_unit),
TALER_PQ_result_spec_amount_with_currency ("price",
&pd->price),
TALER_PQ_result_spec_json ("taxes",
- &pd->taxes),
+ &my_taxes),
GNUNET_PQ_result_spec_uint64 ("total_stock",
&pd->total_stock),
GNUNET_PQ_result_spec_uint64 ("total_sold",
@@ -101,9 +109,9 @@ TMH_PG_lookup_product (void *cls,
GNUNET_PQ_result_spec_uint64 ("total_lost",
&pd->total_lost),
GNUNET_PQ_result_spec_string ("image",
- &pd->image),
+ &my_image),
TALER_PQ_result_spec_json ("address",
- &pd->address),
+ &my_address),
GNUNET_PQ_result_spec_timestamp ("next_restock",
&pd->next_restock),
GNUNET_PQ_result_spec_uint32 ("minimum_age",
@@ -111,14 +119,32 @@ TMH_PG_lookup_product (void *cls,
GNUNET_PQ_result_spec_array_uint64 (pg->conn,
"categories",
num_categories,
- categories),
+ &my_categories),
GNUNET_PQ_result_spec_end
};
+ enum GNUNET_DB_QueryStatus qs;
check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_product",
- params,
- rs);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_product",
+ params,
+ rs);
+ pd->description = my_description;
+ pd->description_i18n = my_description_i18n;
+ pd->unit = my_unit;
+ pd->taxes = my_taxes;
+ pd->image = my_image;
+ pd->address = my_address;
+ *categories = my_categories;
+ /* Clear original pointers to that cleanup_result doesn't squash them */
+ my_description = NULL;
+ my_description_i18n = NULL;
+ my_unit = NULL;
+ my_taxes = NULL;
+ my_image = NULL;
+ my_address = NULL;
+ my_categories = NULL;
+ GNUNET_PQ_cleanup_result (rs);
+ return qs;
}
}
diff --git a/src/bank/Makefile.am b/src/bank/Makefile.am
@@ -10,7 +10,7 @@ lib_LTLIBRARIES = \
libtalermerchantbank.la
libtalermerchantbank_la_LDFLAGS = \
- -version-info 0:0:0 \
+ -version-info 0:1:0 \
-no-undefined
libtalermerchantbank_la_SOURCES = \
mb_common.c mb_common.h \
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
@@ -24,7 +24,7 @@ lib_LTLIBRARIES = \
libtalermerchanttesting.la
libtalermerchanttesting_la_LDFLAGS = \
- -version-info 4:0:1 \
+ -version-info 4:1:1 \
-no-undefined
libtalermerchanttesting_la_SOURCES = \
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
@@ -50,7 +50,7 @@ libtalermerchantutil_la_LIBADD = \
-ltalerutil \
$(XLIB)
libtalermerchantutil_la_LDFLAGS = \
- -version-info 1:0:1 \
+ -version-info 1:1:1 \
-export-dynamic -no-undefined
test_contract_SOURCES = \