From 809300158caaa0215c36ef89c7e38f0edfa93593 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 13:26:00 +0200 Subject: code cleanup, fixing misc. memory leaks in the process --- src/lib/exchange_api_batch_deposit.c | 11 +++----- src/lib/exchange_api_common.c | 23 +++++++--------- src/lib/exchange_api_handle.c | 30 +++++++++------------ src/lib/exchange_api_kyc_check.c | 6 ++--- src/lib/exchange_api_link.c | 27 +++++-------------- src/lib/exchange_api_lookup_aml_decision.c | 25 +++++++++-------- src/lib/exchange_api_lookup_aml_decisions.c | 6 ++--- src/lib/exchange_api_management_get_keys.c | 18 ++++++------- src/lib/exchange_api_refreshes_reveal.c | 17 +++--------- src/lib/exchange_api_refund.c | 37 +++++--------------------- src/lib/exchange_api_reserves_attest.c | 6 ++--- src/lib/exchange_api_reserves_get_attestable.c | 8 +++--- src/lib/exchange_api_reserves_history.c | 8 +++--- src/lib/exchange_api_reserves_status.c | 7 +++-- src/lib/exchange_api_transfers_get.c | 13 +++------ 15 files changed, 84 insertions(+), 158 deletions(-) (limited to 'src/lib') diff --git a/src/lib/exchange_api_batch_deposit.c b/src/lib/exchange_api_batch_deposit.c index c583d5add..544407a38 100644 --- a/src/lib/exchange_api_batch_deposit.c +++ b/src/lib/exchange_api_batch_deposit.c @@ -237,12 +237,12 @@ handle_deposit_finished (void *cls, case MHD_HTTP_OK: { const struct TALER_EXCHANGE_Keys *key_state; - json_t *sigs; + const json_t *sigs; json_t *sig; unsigned int idx; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("exchange_sigs", - &sigs), + GNUNET_JSON_spec_array_const ("exchange_sigs", + &sigs), GNUNET_JSON_spec_fixed_auto ("exchange_pub", &dh->exchange_pub), GNUNET_JSON_spec_mark_optional ( @@ -269,7 +269,6 @@ handle_deposit_finished (void *cls, GNUNET_break_op (0); dr.hr.http_status = 0; dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - GNUNET_JSON_parse_free (spec); break; } dh->exchange_sigs = GNUNET_new_array (dh->num_cdds, @@ -282,7 +281,6 @@ handle_deposit_finished (void *cls, GNUNET_break_op (0); dr.hr.http_status = 0; dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; - GNUNET_JSON_parse_free (spec); break; } json_array_foreach (sigs, idx, sig) @@ -303,7 +301,6 @@ handle_deposit_finished (void *cls, GNUNET_break_op (0); dr.hr.http_status = 0; dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - GNUNET_JSON_parse_free (spec); break; } dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state, @@ -332,14 +329,12 @@ handle_deposit_finished (void *cls, GNUNET_break_op (0); dr.hr.http_status = 0; dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; - GNUNET_JSON_parse_free (spec); break; } } TEAH_get_auditors_for_dc (dh->exchange, &auditor_cb, dh); - GNUNET_JSON_parse_free (spec); } dr.details.ok.exchange_sigs = dh->exchange_sigs; dr.details.ok.exchange_pub = &dh->exchange_pub; diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c index 588b12834..8bbc6c472 100644 --- a/src/lib/exchange_api_common.c +++ b/src/lib/exchange_api_common.c @@ -1465,7 +1465,7 @@ enum GNUNET_GenericReturnValue TALER_EXCHANGE_verify_coin_history ( const struct TALER_EXCHANGE_DenomPublicKey *dk, const struct TALER_CoinSpendPublicKeyP *coin_pub, - json_t *history, + const json_t *history, struct TALER_Amount *total) { const char *currency = dk->value.currency; @@ -1865,7 +1865,7 @@ TALER_EXCHANGE_check_coin_amount_conflict_ ( struct TALER_CoinSpendPublicKeyP *coin_pub, struct TALER_Amount *remaining) { - json_t *history; + const json_t *history; struct TALER_Amount total; struct TALER_DenominationHashP h_denom_pub; const struct TALER_EXCHANGE_DenomPublicKey *dki; @@ -1874,8 +1874,8 @@ TALER_EXCHANGE_check_coin_amount_conflict_ ( coin_pub), GNUNET_JSON_spec_fixed_auto ("h_denom_pub", &h_denom_pub), - GNUNET_JSON_spec_json ("history", - &history), + GNUNET_JSON_spec_array_const ("history", + &history), GNUNET_JSON_spec_end () }; @@ -1902,10 +1902,8 @@ TALER_EXCHANGE_check_coin_amount_conflict_ ( &total)) { GNUNET_break_op (0); - json_decref (history); return GNUNET_SYSERR; } - json_decref (history); if (0 > TALER_amount_subtract (remaining, &dki->value, @@ -2298,8 +2296,8 @@ TALER_EXCHANGE_parse_accounts (const struct TALER_MasterPublicKeyP *master_pub, i++) { struct TALER_EXCHANGE_WireAccount *wa = &was[i]; - json_t *credit_restrictions; - json_t *debit_restrictions; + const json_t *credit_restrictions; + const json_t *debit_restrictions; struct GNUNET_JSON_Specification spec_account[] = { GNUNET_JSON_spec_string ("payto_uri", &wa->payto_uri), @@ -2307,10 +2305,10 @@ TALER_EXCHANGE_parse_accounts (const struct TALER_MasterPublicKeyP *master_pub, GNUNET_JSON_spec_string ("conversion_url", &wa->conversion_url), NULL), - GNUNET_JSON_spec_json ("credit_restrictions", - &credit_restrictions), - GNUNET_JSON_spec_json ("debit_restrictions", - &debit_restrictions), + GNUNET_JSON_spec_array_const ("credit_restrictions", + &credit_restrictions), + GNUNET_JSON_spec_array_const ("debit_restrictions", + &debit_restrictions), GNUNET_JSON_spec_fixed_auto ("master_sig", &wa->master_sig), GNUNET_JSON_spec_end () @@ -2366,7 +2364,6 @@ TALER_EXCHANGE_parse_accounts (const struct TALER_MasterPublicKeyP *master_pub, GNUNET_break_op (0); return GNUNET_SYSERR; } - GNUNET_JSON_parse_free (spec_account); } /* end 'for all accounts */ return GNUNET_OK; } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 601b163db..d78b6185b 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -400,7 +400,7 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, json_t *auditor_obj, const struct TALER_EXCHANGE_Keys *key_data) { - json_t *keys; + const json_t *keys; json_t *key; unsigned int len; unsigned int off; @@ -411,8 +411,8 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, &auditor->auditor_pub), GNUNET_JSON_spec_string ("auditor_url", &auditor_url), - GNUNET_JSON_spec_json ("denomination_keys", - &keys), + GNUNET_JSON_spec_array_const ("denomination_keys", + &keys), GNUNET_JSON_spec_end () }; @@ -492,7 +492,6 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, &auditor_sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -501,7 +500,6 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor, off++; } auditor->num_denom_keys = off; - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } @@ -734,7 +732,7 @@ decode_keys_json (const json_t *resp_obj, const char *currency; const char *asset_type; bool tipping_allowed = true; - json_t *wblwk = NULL; + const json_t *wblwk = NULL; struct GNUNET_JSON_Specification mspec[] = { GNUNET_JSON_spec_fixed_auto ("denominations_sig", &denominations_sig), @@ -755,8 +753,8 @@ decode_keys_json (const json_t *resp_obj, &tipping_allowed), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("wallet_balance_limit_without_kyc", - &wblwk), + GNUNET_JSON_spec_array_const ("wallet_balance_limit_without_kyc", + &wblwk), NULL), GNUNET_JSON_spec_end () }; @@ -908,14 +906,14 @@ decode_keys_json (const json_t *resp_obj, /* TODO: maybe lift all this into a FP in TALER_Extension ? */ { struct TALER_MasterSignatureP extensions_sig = {0}; - json_t *manifests = NULL; + const json_t *manifests = NULL; bool no_extensions = false; bool no_signature = false; struct GNUNET_JSON_Specification ext_spec[] = { GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("extensions", - &manifests), + GNUNET_JSON_spec_object_const ("extensions", + &manifests), &no_extensions), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_fixed_auto ( @@ -1707,15 +1705,15 @@ static void deserialize_data (struct TALER_EXCHANGE_Handle *exchange, const json_t *data) { - json_t *keys; + const json_t *keys; const char *url; uint32_t version; struct GNUNET_TIME_Timestamp expire; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_uint32 ("version", &version), - GNUNET_JSON_spec_json ("keys", - &keys), + GNUNET_JSON_spec_array_const ("keys", + &keys), GNUNET_JSON_spec_string ("exchange_url", &url), GNUNET_JSON_spec_timestamp ("expire", @@ -1742,14 +1740,12 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange, } if (0 != version) { - GNUNET_JSON_parse_free (spec); return; /* unsupported version */ } if (0 != strcmp (url, exchange->url)) { GNUNET_break (0); - GNUNET_JSON_parse_free (spec); return; } memset (&key_data, @@ -1762,7 +1758,6 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange, &kresp.details.ok.compat)) { GNUNET_break (0); - GNUNET_JSON_parse_free (spec); return; } /* decode successful, initialize with the result */ @@ -1777,7 +1772,6 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange, /* notify application about the key information */ exchange->cert_cb (exchange->cert_cb_cls, &kresp); - GNUNET_JSON_parse_free (spec); } diff --git a/src/lib/exchange_api_kyc_check.c b/src/lib/exchange_api_kyc_check.c index d1580e76c..472a7d2d2 100644 --- a/src/lib/exchange_api_kyc_check.c +++ b/src/lib/exchange_api_kyc_check.c @@ -96,7 +96,7 @@ handle_kyc_check_finished (void *cls, break; case MHD_HTTP_OK: { - json_t *kyc_details; + const json_t *kyc_details; uint32_t status; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("exchange_sig", @@ -105,8 +105,8 @@ handle_kyc_check_finished (void *cls, &ks.details.ok.exchange_pub), GNUNET_JSON_spec_timestamp ("now", &ks.details.ok.timestamp), - GNUNET_JSON_spec_json ("kyc_details", - &kyc_details), + GNUNET_JSON_spec_object_const ("kyc_details", + &kyc_details), GNUNET_JSON_spec_uint32 ("aml_status", &status), GNUNET_JSON_spec_end () diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c index 3b998f23a..c2b7ac0b4 100644 --- a/src/lib/exchange_api_link.c +++ b/src/lib/exchange_api_link.c @@ -270,9 +270,10 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh, whilst 'i' and 'session' track the 2d array. */// for (session = 0; sessioncollection_time), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("attributes", - &attributes), + GNUNET_JSON_spec_object_const ("attributes", + &kyc->attributes), NULL), GNUNET_JSON_spec_string ("provider_section", &kyc->provider_section), @@ -149,8 +148,6 @@ parse_kyc_attributes (const json_t *kyc_attributes, GNUNET_break_op (0); return GNUNET_SYSERR; } - kyc->attributes = attributes; - json_decref (attributes); /* this is OK, RC preserved via 'kyc_attributes' as long as needed! */ } return GNUNET_OK; } @@ -171,13 +168,13 @@ parse_decision_ok (struct TALER_EXCHANGE_LookupAmlDecision *lh, .hr.reply = json, .hr.http_status = MHD_HTTP_OK }; - json_t *aml_history; - json_t *kyc_attributes; + const json_t *aml_history; + const json_t *kyc_attributes; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("aml_history", - &aml_history), - GNUNET_JSON_spec_json ("kyc_attributes", - &kyc_attributes), + GNUNET_JSON_spec_array_const ("aml_history", + &aml_history), + GNUNET_JSON_spec_array_const ("kyc_attributes", + &kyc_attributes), GNUNET_JSON_spec_end () }; @@ -199,6 +196,12 @@ parse_decision_ok (struct TALER_EXCHANGE_LookupAmlDecision *lh, GNUNET_NZL (lr.details.ok.kyc_attributes_length)]; enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR; + memset (aml_history_ar, + 0, + sizeof (aml_history_ar)); + memset (kyc_attributes_ar, + 0, + sizeof (kyc_attributes_ar)); lr.details.ok.aml_history = aml_history_ar; lr.details.ok.kyc_attributes = kyc_attributes_ar; ret = parse_aml_history (aml_history, diff --git a/src/lib/exchange_api_lookup_aml_decisions.c b/src/lib/exchange_api_lookup_aml_decisions.c index 403acb54a..22222b1e4 100644 --- a/src/lib/exchange_api_lookup_aml_decisions.c +++ b/src/lib/exchange_api_lookup_aml_decisions.c @@ -123,10 +123,10 @@ parse_decisions_ok (struct TALER_EXCHANGE_LookupAmlDecisions *lh, .hr.reply = json, .hr.http_status = MHD_HTTP_OK }; - json_t *records; + const json_t *records; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("records", - &records), + GNUNET_JSON_spec_array_const ("records", + &records), GNUNET_JSON_spec_end () }; diff --git a/src/lib/exchange_api_management_get_keys.c b/src/lib/exchange_api_management_get_keys.c index c649f397f..df14f2e70 100644 --- a/src/lib/exchange_api_management_get_keys.c +++ b/src/lib/exchange_api_management_get_keys.c @@ -85,14 +85,14 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh, }; struct TALER_EXCHANGE_FutureKeys *fk = &gkr.details.ok.keys; - json_t *sk; - json_t *dk; + const json_t *sk; + const json_t *dk; bool ok; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("future_denoms", - &dk), - GNUNET_JSON_spec_json ("future_signkeys", - &sk), + GNUNET_JSON_spec_array_const ("future_denoms", + &dk), + GNUNET_JSON_spec_array_const ("future_signkeys", + &sk), GNUNET_JSON_spec_fixed_auto ("master_pub", &fk->master_pub), GNUNET_JSON_spec_fixed_auto ("denom_secmod_public_key", @@ -127,7 +127,7 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh, i); struct TALER_EXCHANGE_FutureSigningPublicKey *sign_key = &fk->sign_keys[i]; - struct GNUNET_JSON_Specification spec[] = { + struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_fixed_auto ("key", &sign_key->key), GNUNET_JSON_spec_fixed_auto ("signkey_secmod_sig", @@ -143,7 +143,7 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh, if (GNUNET_OK != GNUNET_JSON_parse (j, - spec, + ispec, NULL, NULL)) { GNUNET_break_op (0); @@ -276,7 +276,6 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh, break; } } - GNUNET_JSON_parse_free (spec); if (! ok) break; } @@ -289,7 +288,6 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh, TALER_denom_pub_free (&fk->denom_keys[i].key); GNUNET_free (fk->sign_keys); GNUNET_free (fk->denom_keys); - GNUNET_JSON_parse_free (spec); return (ok) ? GNUNET_OK : GNUNET_SYSERR; } diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c index 3bdef2020..50de76810 100644 --- a/src/lib/exchange_api_refreshes_reveal.c +++ b/src/lib/exchange_api_refreshes_reveal.c @@ -107,10 +107,10 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, const json_t *json, struct TALER_EXCHANGE_RevealedCoinInfo *rcis) { - json_t *jsona; + const json_t *jsona; struct GNUNET_JSON_Specification outer_spec[] = { - GNUNET_JSON_spec_json ("ev_sigs", - &jsona), + GNUNET_JSON_spec_array_const ("ev_sigs", + &jsona), GNUNET_JSON_spec_end () }; @@ -122,18 +122,10 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, GNUNET_break_op (0); return GNUNET_SYSERR; } - if (! json_is_array (jsona)) - { - /* We expected an array of coins */ - GNUNET_break_op (0); - GNUNET_JSON_parse_free (outer_spec); - return GNUNET_SYSERR; - } if (rrh->md.num_fresh_coins != json_array_size (jsona)) { /* Number of coins generated does not match our expectation */ GNUNET_break_op (0); - GNUNET_JSON_parse_free (outer_spec); return GNUNET_SYSERR; } for (unsigned int i = 0; imd.num_fresh_coins; i++) @@ -180,7 +172,6 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (outer_spec); return GNUNET_SYSERR; } @@ -209,13 +200,11 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh, { GNUNET_break_op (0); GNUNET_JSON_parse_free (spec); - GNUNET_JSON_parse_free (outer_spec); return GNUNET_SYSERR; } GNUNET_JSON_parse_free (spec); rci->sig = coin.sig; } - GNUNET_JSON_parse_free (outer_spec); return GNUNET_OK; } diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c index 7c9616ea5..35524ca4b 100644 --- a/src/lib/exchange_api_refund.c +++ b/src/lib/exchange_api_refund.c @@ -172,11 +172,11 @@ static enum GNUNET_GenericReturnValue verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, const json_t *json) { - json_t *history; + const json_t *history; struct TALER_DenominationHashP h_denom_pub; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("history", - &history), + GNUNET_JSON_spec_array_const ("history", + &history), GNUNET_JSON_spec_fixed_auto ("h_denom_pub", &h_denom_pub), GNUNET_JSON_spec_end () @@ -199,7 +199,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, if (0 == len) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } have_deposit = false; @@ -225,7 +224,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (0 == strcasecmp (type, @@ -274,7 +272,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -292,7 +289,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if ( (0 != GNUNET_memcmp (&rh->h_contract_terms, @@ -302,7 +298,6 @@ 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) @@ -313,7 +308,6 @@ 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 <= @@ -356,7 +350,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (0 > @@ -365,7 +358,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &amount)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -377,7 +369,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if ( (0 != GNUNET_memcmp (&rh->h_contract_terms, @@ -387,7 +378,6 @@ 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 (rtransaction_id == rh->rtransaction_id) @@ -395,7 +385,6 @@ 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; } @@ -406,7 +395,6 @@ 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 <= @@ -427,7 +415,6 @@ 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; } } @@ -440,7 +427,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, &rh->refund_amount)) { GNUNET_break (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -452,7 +438,6 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, if (! have_deposit) { GNUNET_break (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (-1 != TALER_amount_cmp (&dtotal, @@ -460,11 +445,9 @@ verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh, { /* rtotal <= dtotal is fine, no conflict! */ GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } /* dtotal < rtotal: that's a conflict! */ - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } @@ -482,11 +465,11 @@ static enum GNUNET_GenericReturnValue verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, const json_t *json) { - json_t *h; + const json_t *h; json_t *e; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("history", - &h), + GNUNET_JSON_spec_array_const ("history", + &h), GNUNET_JSON_spec_end () }; @@ -498,11 +481,9 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, GNUNET_break_op (0); return GNUNET_SYSERR; } - if ( (! json_is_array (h)) || - (1 != json_array_size (h) ) ) + if (1 != json_array_size (h)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } e = json_array_get (h, 0); @@ -538,7 +519,6 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -550,7 +530,6 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, &sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if ( (rtransaction_id != rh->rtransaction_id) || @@ -562,11 +541,9 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh, &amount)) ) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } diff --git a/src/lib/exchange_api_reserves_attest.c b/src/lib/exchange_api_reserves_attest.c index 0a9134e85..82d5785b7 100644 --- a/src/lib/exchange_api_reserves_attest.c +++ b/src/lib/exchange_api_reserves_attest.c @@ -93,7 +93,7 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh, .hr.reply = j, .hr.http_status = MHD_HTTP_OK }; - json_t *attributes; + const json_t *attributes; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_timestamp ("exchange_timestamp", &rs.details.ok.exchange_time), @@ -103,8 +103,8 @@ handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh, &rs.details.ok.exchange_sig), GNUNET_JSON_spec_fixed_auto ("exchange_pub", &rs.details.ok.exchange_pub), - GNUNET_JSON_spec_json ("attributes", - &attributes), + GNUNET_JSON_spec_object_const ("attributes", + &attributes), GNUNET_JSON_spec_end () }; diff --git a/src/lib/exchange_api_reserves_get_attestable.c b/src/lib/exchange_api_reserves_get_attestable.c index 3a5fd25d8..b272d478a 100644 --- a/src/lib/exchange_api_reserves_get_attestable.c +++ b/src/lib/exchange_api_reserves_get_attestable.c @@ -88,10 +88,10 @@ handle_reserves_get_attestable_ok ( .hr.reply = j, .hr.http_status = MHD_HTTP_OK }; - json_t *details; + const json_t *details; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("details", - &details), + GNUNET_JSON_spec_array_const ("details", + &details), GNUNET_JSON_spec_end () }; @@ -116,7 +116,6 @@ handle_reserves_get_attestable_ok ( if (NULL == attributes[i]) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -126,7 +125,6 @@ handle_reserves_get_attestable_ok ( &rs); rgah->cb = NULL; } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c index 2a0dd5651..ccc11a270 100644 --- a/src/lib/exchange_api_reserves_history.c +++ b/src/lib/exchange_api_reserves_history.c @@ -99,7 +99,7 @@ static enum GNUNET_GenericReturnValue handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, const json_t *j) { - json_t *history; + const json_t *history; unsigned int len; struct TALER_EXCHANGE_ReserveHistory rs = { .hr.reply = j, @@ -110,8 +110,8 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", &rs.details.ok.balance), - GNUNET_JSON_spec_json ("history", - &history), + GNUNET_JSON_spec_array_const ("history", + &history), GNUNET_JSON_spec_end () }; @@ -143,7 +143,6 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, GNUNET_break_op (0); TALER_EXCHANGE_free_reserve_history (rhistory, len); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (NULL != rsh->cb) @@ -157,7 +156,6 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh, TALER_EXCHANGE_free_reserve_history (rhistory, len); } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_status.c index 27f63d244..57fb04276 100644 --- a/src/lib/exchange_api_reserves_status.c +++ b/src/lib/exchange_api_reserves_status.c @@ -89,7 +89,7 @@ static enum GNUNET_GenericReturnValue handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh, const json_t *j) { - json_t *history; + const json_t *history; unsigned int len; struct TALER_EXCHANGE_ReserveStatus rs = { .hr.reply = j, @@ -98,8 +98,8 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh, struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", &rs.details.ok.balance), - GNUNET_JSON_spec_json ("history", - &history), + GNUNET_JSON_spec_array_const ("history", + &history), GNUNET_JSON_spec_end () }; @@ -145,7 +145,6 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh, TALER_EXCHANGE_free_reserve_history (rhistory, len); } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c index f00e36ce3..3a5a64fd5 100644 --- a/src/lib/exchange_api_transfers_get.c +++ b/src/lib/exchange_api_transfers_get.c @@ -84,7 +84,7 @@ check_transfers_get_response_ok ( struct TALER_EXCHANGE_TransfersGetHandle *wdh, const json_t *json) { - json_t *details_j; + const json_t *details_j; struct TALER_Amount total_expected; struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_EXCHANGE_TransfersGetResponse tgr = { @@ -104,8 +104,8 @@ check_transfers_get_response_ok ( &td->h_payto), GNUNET_JSON_spec_timestamp ("execution_time", &td->execution_time), - GNUNET_JSON_spec_json ("deposits", - &details_j), + GNUNET_JSON_spec_array_const ("deposits", + &details_j), GNUNET_JSON_spec_fixed_auto ("exchange_sig", &td->exchange_sig), GNUNET_JSON_spec_fixed_auto ("exchange_pub", @@ -126,7 +126,6 @@ check_transfers_get_response_ok ( &total_expected)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (GNUNET_OK != @@ -135,7 +134,6 @@ check_transfers_get_response_ok ( &td->exchange_pub)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } td->details_length = json_array_size (details_j); @@ -181,7 +179,6 @@ check_transfers_get_response_ok ( { GNUNET_break_op (0); GNUNET_CRYPTO_hash_context_abort (hash_context); - GNUNET_JSON_parse_free (spec); GNUNET_free (details); return GNUNET_SYSERR; } @@ -211,7 +208,6 @@ check_transfers_get_response_ok ( &td->exchange_sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); GNUNET_free (details); return GNUNET_SYSERR; } @@ -223,7 +219,6 @@ check_transfers_get_response_ok ( &td->wire_fee)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); GNUNET_free (details); return GNUNET_SYSERR; } @@ -232,7 +227,6 @@ check_transfers_get_response_ok ( &td->total_amount)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); GNUNET_free (details); return GNUNET_SYSERR; } @@ -240,7 +234,6 @@ check_transfers_get_response_ok ( &tgr); GNUNET_free (details); } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } -- cgit v1.2.3