From 52fe9d657bd54e622e8b87070c29ac0ffc27c575 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 19 Nov 2021 20:56:53 +0100 Subject: -fix leaks and compiler warnings --- src/lib/exchange_api_common.c | 2 +- src/lib/exchange_api_refresh_common.c | 9 ++++++--- src/lib/exchange_api_refund.c | 38 +++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src/lib') diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 900c871d2..38c4ce1a3 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -679,7 +679,7 @@ TALER_EXCHANGE_verify_coin_history ( for the exchange to lie here, so not checking is probably OK (an auditor ought to check, though). Then again, we similarly had no reason to check the merchant's signature (other than a - well-formendess check). */// + well-formendess check). */ /* check that refund fee matches our expectations from /keys! */ if (NULL != dk) diff --git a/src/lib/exchange_api_refresh_common.c b/src/lib/exchange_api_refresh_common.c index 520c80fd4..4f2a2cf18 100644 --- a/src/lib/exchange_api_refresh_common.c +++ b/src/lib/exchange_api_refresh_common.c @@ -198,11 +198,11 @@ serialize_melt_data (const struct MeltData *md) GNUNET_JSON_pack_data_auto ("ps", &md->fresh_coins[j][i])); GNUNET_assert (0 == - json_array_append (planchet_secrets, - ps)); + json_array_append_new (planchet_secrets, + ps)); } GNUNET_assert (0 == - json_array_append ( + json_array_append_new ( fresh_coins, GNUNET_JSON_PACK ( TALER_JSON_pack_denom_pub ("denom_pub", @@ -299,6 +299,7 @@ TALER_EXCHANGE_deserialize_melt_data_ (const json_t *melt_data, { GNUNET_break (0); ok = false; + GNUNET_JSON_parse_free (ispec); break; } for (unsigned int j = 0; jdepconf.h_contract_terms, @@ -256,6 +260,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, { /* deposit information is about a different merchant/contract */ GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (have_deposit) @@ -266,6 +271,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &dtotal)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } GNUNET_break (0 <= @@ -290,7 +296,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND), .coin_pub = rh->depconf.coin_pub }; - struct GNUNET_JSON_Specification spec[] = { + struct GNUNET_JSON_Specification ispec[] = { TALER_JSON_spec_amount_any ("refund_fee", &refund_fee), GNUNET_JSON_spec_fixed_auto ("merchant_sig", @@ -306,10 +312,11 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, if (GNUNET_OK != GNUNET_JSON_parse (transaction, - spec, + ispec, NULL, NULL)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (0 > @@ -318,6 +325,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &amount)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } TALER_amount_hton (&rr.refund_amount, @@ -330,6 +338,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rr.merchant.eddsa_pub)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if ( (0 != GNUNET_memcmp (&rh->depconf.h_contract_terms, @@ -339,6 +348,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, { /* refund is about a different merchant/contract */ GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (rr.rtransaction_id == rh->depconf.rtransaction_id) @@ -346,6 +356,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, /* Eh, this shows either a dependency failure or idempotency, but must not happen in a conflict reply. Fail! */ GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -356,6 +367,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rtotal)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } GNUNET_break (0 <= @@ -376,6 +388,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, "Unexpected type `%s' in response for exchange refund\n", type); GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -393,6 +406,7 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &amount)) { GNUNET_break (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -405,10 +419,12 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rtotal)) { /* dtotal < rtotal: good! */ + GNUNET_JSON_parse_free (spec); return GNUNET_OK; } /* this fails to prove a conflict */ GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -422,14 +438,15 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, * @param json json reply with the signature * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not */ -static int +static enum GNUNET_GenericReturnValue verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, const json_t *json) { json_t *h; json_t *e; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("history", &h), + GNUNET_JSON_spec_json ("history", + &h), GNUNET_JSON_spec_end () }; @@ -445,6 +462,7 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, (1 != json_array_size (h) ) ) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } e = json_array_get (h, 0); @@ -459,7 +477,7 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, .coin_pub = rh->depconf.coin_pub }; uint64_t rtransaction_id; - struct GNUNET_JSON_Specification spec[] = { + struct GNUNET_JSON_Specification ispec[] = { TALER_JSON_spec_amount_any ("amount", &amount), GNUNET_JSON_spec_string ("type", @@ -479,10 +497,11 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, if (GNUNET_OK != GNUNET_JSON_parse (e, - spec, + ispec, NULL, NULL)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } rr.rtransaction_id = GNUNET_htonll (rtransaction_id); @@ -495,6 +514,7 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rh->depconf.merchant.eddsa_pub)) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if ( (rr.rtransaction_id != rh->depconf.rtransaction_id) || @@ -506,9 +526,11 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rr.refund_amount)) ) { GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } + GNUNET_JSON_parse_free (spec); return GNUNET_OK; } -- cgit v1.2.3