summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-07-10 10:23:52 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-07-10 10:23:52 +0200
commit3024dc9fa54e8677b4816e56f8d215556a7d5561 (patch)
treeaaf2281e1c69327d4b91565d3b75c0a6fa36165a /src/testing
parent9d706a01a23e36e1c349d06e7a1be8bb44b7f0d5 (diff)
downloadexchange-3024dc9fa54e8677b4816e56f8d215556a7d5561.tar.gz
exchange-3024dc9fa54e8677b4816e56f8d215556a7d5561.tar.bz2
exchange-3024dc9fa54e8677b4816e56f8d215556a7d5561.zip
fix memory leaks reported by valgrind
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_bank_api.c3
-rw-r--r--src/testing/test_exchange_api.c1
-rw-r--r--src/testing/testing_api_cmd_batch_withdraw.c37
-rw-r--r--src/testing/testing_api_cmd_deposit.c33
-rw-r--r--src/testing/testing_api_cmd_refresh.c45
-rw-r--r--src/testing/testing_api_cmd_run_fakebank.c2
-rw-r--r--src/testing/testing_api_cmd_withdraw.c40
7 files changed, 87 insertions, 74 deletions
diff --git a/src/testing/test_bank_api.c b/src/testing/test_bank_api.c
index e197b152c..8f1fe2960 100644
--- a/src/testing/test_bank_api.c
+++ b/src/testing/test_bank_api.c
@@ -78,6 +78,9 @@ run (void *cls,
case TALER_TESTING_BS_IBAN:
ssoptions = "-ns";
break;
+ default:
+ ssoptions = NULL;
+ break;
}
memset (&wtid,
42,
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c
index e8cc6659f..8ecf5d5ba 100644
--- a/src/testing/test_exchange_api.c
+++ b/src/testing/test_exchange_api.c
@@ -660,7 +660,6 @@ run (void *cls,
"refresh-reveal-age-1",
MHD_HTTP_CONFLICT,
NULL),
-
TALER_TESTING_cmd_end ()
};
diff --git a/src/testing/testing_api_cmd_batch_withdraw.c b/src/testing/testing_api_cmd_batch_withdraw.c
index 184e02bfd..da43a9aa9 100644
--- a/src/testing/testing_api_cmd_batch_withdraw.c
+++ b/src/testing/testing_api_cmd_batch_withdraw.c
@@ -79,10 +79,10 @@ struct CoinState
/**
* If age > 0, put here the corresponding age commitment with its proof and
- * its hash, respectivelly, NULL otherwise.
+ * its hash, respectivelly.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Reserve history entry that corresponds to this coin.
@@ -316,7 +316,7 @@ batch_withdraw_run (void *cls,
wci->pk = cs->pk;
wci->ps = &cs->ps;
- wci->ach = cs->h_age_commitment;
+ wci->ach = &cs->h_age_commitment;
}
ws->wsh = TALER_EXCHANGE_batch_withdraw (
TALER_TESTING_interpreter_get_context (is),
@@ -366,13 +366,8 @@ batch_withdraw_cleanup (void *cls,
TALER_EXCHANGE_destroy_denomination_key (cs->pk);
cs->pk = NULL;
}
- if (NULL != cs->age_commitment_proof)
- {
- TALER_age_commitment_proof_free (cs->age_commitment_proof);
- cs->age_commitment_proof = NULL;
- }
- if (NULL != cs->h_age_commitment)
- GNUNET_free (cs->h_age_commitment);
+ if (0 < ws->age)
+ TALER_age_commitment_proof_free (&cs->age_commitment_proof);
}
GNUNET_free (ws->coins);
GNUNET_free (ws->exchange_url);
@@ -424,9 +419,13 @@ batch_withdraw_traits (void *cls,
TALER_TESTING_make_trait_payto_uri (ws->reserve_payto_uri),
TALER_TESTING_make_trait_exchange_url (ws->exchange_url),
TALER_TESTING_make_trait_age_commitment_proof (index,
- cs->age_commitment_proof),
+ ws->age > 0 ?
+ &cs->age_commitment_proof:
+ NULL),
TALER_TESTING_make_trait_h_age_commitment (index,
- cs->h_age_commitment),
+ ws->age > 0 ?
+ &cs->h_age_commitment :
+ NULL),
TALER_TESTING_trait_end ()
};
@@ -473,13 +472,9 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
if (0 < age)
{
- struct TALER_AgeCommitmentProof *acp;
- struct TALER_AgeCommitmentHash *hac;
struct GNUNET_HashCode seed;
struct TALER_AgeMask mask;
- acp = GNUNET_new (struct TALER_AgeCommitmentProof);
- hac = GNUNET_new (struct TALER_AgeCommitmentHash);
mask = TALER_extensions_get_age_restriction_mask ();
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
@@ -490,7 +485,7 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
&mask,
age,
&seed,
- acp))
+ &cs->age_commitment_proof))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to generate age commitment for age %d at %s\n",
@@ -499,10 +494,8 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
GNUNET_assert (0);
}
- TALER_age_commitment_hash (&acp->commitment,
- hac);
- cs->age_commitment_proof = acp;
- cs->h_age_commitment = hac;
+ TALER_age_commitment_hash (&cs->age_commitment_proof.commitment,
+ &cs->h_age_commitment);
}
if (GNUNET_OK !=
diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c
index 2fa0141fa..5c98f91a1 100644
--- a/src/testing/testing_api_cmd_deposit.c
+++ b/src/testing/testing_api_cmd_deposit.c
@@ -284,8 +284,7 @@ deposit_run (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
struct TALER_CoinSpendPublicKeyP coin_pub;
- const struct TALER_AgeCommitmentProof *age_commitment_proof = NULL;
- struct TALER_AgeCommitmentHash h_age_commitment = {0};
+ const struct TALER_AgeCommitmentHash *phac;
const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
const struct TALER_DenominationSignature *denom_pub_sig;
struct TALER_CoinSpendSignatureP coin_sig;
@@ -389,9 +388,9 @@ deposit_run (void *cls,
ds->coin_index,
&coin_priv)) ||
(GNUNET_OK !=
- TALER_TESTING_get_trait_age_commitment_proof (coin_cmd,
- ds->coin_index,
- &age_commitment_proof)) ||
+ TALER_TESTING_get_trait_h_age_commitment (coin_cmd,
+ ds->coin_index,
+ &phac)) ||
(GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (coin_cmd,
ds->coin_index,
@@ -409,11 +408,6 @@ deposit_run (void *cls,
return;
}
- if (NULL != age_commitment_proof)
- {
- TALER_age_commitment_hash (&age_commitment_proof->commitment,
- &h_age_commitment);
- }
ds->deposit_fee = denom_pub->fees.deposit;
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
@@ -447,7 +441,7 @@ deposit_run (void *cls,
&denom_pub->fees.deposit,
&h_wire,
&h_contract_terms,
- &h_age_commitment,
+ phac,
NULL, /* FIXME #7270: add hash of extensions */
&denom_pub->h_key,
ds->wallet_timestamp,
@@ -460,11 +454,11 @@ deposit_run (void *cls,
{
struct TALER_EXCHANGE_CoinDepositDetail cdd = {
.amount = ds->amount,
- .h_age_commitment = h_age_commitment,
.coin_pub = coin_pub,
.coin_sig = coin_sig,
.denom_sig = *denom_pub_sig,
- .h_denom_pub = denom_pub->h_key
+ .h_denom_pub = denom_pub->h_key,
+ .h_age_commitment = {{{0}}},
};
struct TALER_EXCHANGE_DepositContractDetail dcd = {
.wire_deadline = ds->wire_deadline,
@@ -477,6 +471,9 @@ deposit_run (void *cls,
.refund_deadline = ds->refund_deadline
};
+ if (NULL != phac)
+ cdd.h_age_commitment = *phac;
+
ds->dh = TALER_EXCHANGE_batch_deposit (
TALER_TESTING_interpreter_get_context (is),
exchange_url,
@@ -551,6 +548,7 @@ deposit_traits (void *cls,
/* Will point to coin cmd internals. */
const struct TALER_CoinSpendPrivateKeyP *coin_spent_priv;
const struct TALER_AgeCommitmentProof *age_commitment_proof;
+ const struct TALER_AgeCommitmentHash *h_age_commitment;
if (GNUNET_YES != ds->command_initialized)
{
@@ -575,12 +573,17 @@ deposit_traits (void *cls,
(GNUNET_OK !=
TALER_TESTING_get_trait_age_commitment_proof (coin_cmd,
ds->coin_index,
- &age_commitment_proof)) )
+ &age_commitment_proof)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_h_age_commitment (coin_cmd,
+ ds->coin_index,
+ &h_age_commitment)) )
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return GNUNET_NO;
}
+
{
struct TALER_TESTING_Trait traits[] = {
/* First two traits are only available if
@@ -594,6 +597,8 @@ deposit_traits (void *cls,
coin_spent_priv),
TALER_TESTING_make_trait_age_commitment_proof (0,
age_commitment_proof),
+ TALER_TESTING_make_trait_h_age_commitment (0,
+ h_age_commitment),
TALER_TESTING_make_trait_wire_details (ds->wire_details),
TALER_TESTING_make_trait_contract_terms (ds->contract_terms),
TALER_TESTING_make_trait_merchant_priv (&ds->merchant_priv),
diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c
index 8782b0b5e..3b35a73b9 100644
--- a/src/testing/testing_api_cmd_refresh.c
+++ b/src/testing/testing_api_cmd_refresh.c
@@ -75,7 +75,7 @@ struct TALER_TESTING_FreshCoinData
* applicable.
*/
struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* The blinding key (needed for recoup operations).
@@ -440,8 +440,13 @@ reveal_cb (void *cls,
return;
}
fc->coin_priv = coin->coin_priv;
- fc->age_commitment_proof = coin->age_commitment_proof;
- fc->h_age_commitment = coin->h_age_commitment;
+
+ if (NULL != coin->age_commitment_proof)
+ {
+ fc->age_commitment_proof =
+ TALER_age_commitment_proof_duplicate (coin->age_commitment_proof);
+ fc->h_age_commitment = coin->h_age_commitment;
+ }
TALER_denom_sig_deep_copy (&fc->sig,
&coin->sig);
@@ -559,7 +564,11 @@ refresh_reveal_cleanup (void *cls,
}
for (unsigned int j = 0; j < rrs->num_fresh_coins; j++)
+ {
TALER_denom_sig_free (&rrs->fresh_coins[j].sig);
+ TALER_age_commitment_proof_free (rrs->fresh_coins[j].age_commitment_proof);
+ GNUNET_free (rrs->fresh_coins[j].age_commitment_proof);
+ }
GNUNET_free (rrs->fresh_coins);
GNUNET_free (rrs->psa);
@@ -1024,12 +1033,12 @@ melt_run (void *cls,
{
struct TALER_Amount melt_amount;
struct TALER_Amount fresh_amount;
- const struct TALER_AgeCommitmentProof *age_commitment_proof;
- const struct TALER_AgeCommitmentHash *h_age_commitment;
+ const struct TALER_AgeCommitmentProof *age_commitment_proof = NULL;
+ const struct TALER_AgeCommitmentHash *h_age_commitment = NULL;
const struct TALER_DenominationSignature *melt_sig;
const struct TALER_EXCHANGE_DenomPublicKey *melt_denom_pub;
const struct TALER_TESTING_Command *coin_command;
- bool age_restricted;
+ bool age_restricted_denom;
if (NULL == (coin_command
= TALER_TESTING_interpreter_lookup_command (
@@ -1094,7 +1103,10 @@ melt_run (void *cls,
/* Melt amount starts with the melt fee of the old coin; we'll add the
values and withdraw fees of the fresh coins next */
melt_amount = melt_denom_pub->fees.refresh;
- age_restricted = melt_denom_pub->key.age_mask.bits != 0;
+ age_restricted_denom = melt_denom_pub->key.age_mask.bits != 0;
+ GNUNET_assert (age_restricted_denom == (NULL != age_commitment_proof));
+ GNUNET_assert ((NULL == age_commitment_proof) ||
+ (0 < age_commitment_proof->commitment.num));
for (unsigned int i = 0; i<num_fresh_coins; i++)
{
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
@@ -1113,7 +1125,7 @@ melt_run (void *cls,
}
fresh_pk = TALER_TESTING_find_pk (TALER_TESTING_get_keys (rms->is),
&fresh_amount,
- age_restricted);
+ age_restricted_denom);
if (NULL == fresh_pk)
{
GNUNET_break (0);
@@ -1139,13 +1151,20 @@ melt_run (void *cls,
rms->refresh_data.melt_amount = melt_amount;
rms->refresh_data.melt_sig = *melt_sig;
rms->refresh_data.melt_pk = *melt_denom_pub;
- rms->refresh_data.melt_age_commitment_proof = age_commitment_proof;
- rms->refresh_data.melt_h_age_commitment = h_age_commitment;
+
+ if (NULL != age_commitment_proof)
+ {
+ GNUNET_assert (NULL != h_age_commitment);
+ rms->refresh_data.melt_age_commitment_proof = age_commitment_proof;
+ rms->refresh_data.melt_h_age_commitment = h_age_commitment;
+ }
rms->refresh_data.fresh_pks = rms->fresh_pks;
rms->refresh_data.fresh_pks_len = num_fresh_coins;
- GNUNET_assert (age_restricted ==
+ GNUNET_assert (age_restricted_denom ==
(NULL != age_commitment_proof));
+ GNUNET_assert ((NULL == age_commitment_proof) ||
+ (0 < age_commitment_proof->commitment.num));
rms->rmh = TALER_EXCHANGE_melt (
TALER_TESTING_interpreter_get_context (is),
@@ -1198,6 +1217,7 @@ melt_cleanup (void *cls,
TALER_denom_pub_free (&rms->fresh_pks[i].key);
GNUNET_free (rms->fresh_pks);
}
+
GNUNET_free (rms->mbds);
GNUNET_free (rms->melt_fresh_amounts);
GNUNET_free (rms);
@@ -1409,7 +1429,7 @@ refresh_reveal_traits (void *cls,
rrs->fresh_coins[index].age_commitment_proof),
TALER_TESTING_make_trait_h_age_commitment (
index,
- rrs->fresh_coins[index].h_age_commitment),
+ &rrs->fresh_coins[index].h_age_commitment),
TALER_TESTING_make_trait_denom_pub (
index,
rrs->fresh_coins[index].pk),
@@ -1427,6 +1447,7 @@ refresh_reveal_traits (void *cls,
&rrs->psa[index]),
TALER_TESTING_trait_end ()
};
+
return TALER_TESTING_get_trait (traits,
ret,
trait,
diff --git a/src/testing/testing_api_cmd_run_fakebank.c b/src/testing/testing_api_cmd_run_fakebank.c
index f9a6b9b69..3664f1600 100644
--- a/src/testing/testing_api_cmd_run_fakebank.c
+++ b/src/testing/testing_api_cmd_run_fakebank.c
@@ -110,6 +110,7 @@ run_fakebank_cleanup (void *cls,
}
GNUNET_free (rfs->ba.wire_gateway_url);
GNUNET_free (rfs->bank_url);
+ GNUNET_free (rfs->currency);
GNUNET_free (rfs);
}
@@ -194,6 +195,7 @@ TALER_TESTING_cmd_run_fakebank (
(unsigned int) fakebank_port,
exchange_xtalerbank_account);
GNUNET_free (exchange_xtalerbank_account);
+ GNUNET_free (exchange_payto_uri);
}
rfs->ba.method = TALER_BANK_AUTH_NONE;
{
diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c
index 69a47cb5e..2550e55a4 100644
--- a/src/testing/testing_api_cmd_withdraw.c
+++ b/src/testing/testing_api_cmd_withdraw.c
@@ -144,10 +144,10 @@ struct WithdrawState
/**
* If age > 0, put here the corresponding age commitment with its proof and
- * its hash, respectivelly, NULL otherwise.
+ * its hash, respectivelly.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Reserve history entry that corresponds to this operation.
@@ -438,7 +438,7 @@ withdraw_run (void *cls,
struct TALER_EXCHANGE_WithdrawCoinInput wci = {
.pk = ws->pk,
.ps = &ws->ps,
- .ach = ws->h_age_commitment
+ .ach = 0 < ws->age ? &ws->h_age_commitment : NULL
};
ws->wsh = TALER_EXCHANGE_withdraw (
TALER_TESTING_interpreter_get_context (is),
@@ -489,16 +489,8 @@ withdraw_cleanup (void *cls,
TALER_EXCHANGE_destroy_denomination_key (ws->pk);
ws->pk = NULL;
}
- if (NULL != ws->age_commitment_proof)
- {
- TALER_age_commitment_proof_free (ws->age_commitment_proof);
- ws->age_commitment_proof = NULL;
- }
- if (NULL != ws->h_age_commitment)
- {
- GNUNET_free (ws->h_age_commitment);
- ws->h_age_commitment = NULL;
- }
+ if (ws->age > 0)
+ TALER_age_commitment_proof_free (&ws->age_commitment_proof);
GNUNET_free (ws->exchange_url);
GNUNET_free (ws->reserve_payto_uri);
GNUNET_free (ws);
@@ -545,9 +537,13 @@ withdraw_traits (void *cls,
TALER_TESTING_make_trait_payto_uri (ws->reserve_payto_uri),
TALER_TESTING_make_trait_exchange_url (ws->exchange_url),
TALER_TESTING_make_trait_age_commitment_proof (0,
- ws->age_commitment_proof),
+ 0 < ws->age
+ ? &ws->age_commitment_proof
+ : NULL),
TALER_TESTING_make_trait_h_age_commitment (0,
- ws->h_age_commitment),
+ 0 < ws->age
+ ? &ws->h_age_commitment
+ : NULL),
TALER_TESTING_trait_end ()
};
@@ -573,13 +569,9 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
ws->age = age;
if (0 < age)
{
- struct TALER_AgeCommitmentProof *acp;
- struct TALER_AgeCommitmentHash *hac;
struct GNUNET_HashCode seed;
struct TALER_AgeMask mask;
- acp = GNUNET_new (struct TALER_AgeCommitmentProof);
- hac = GNUNET_new (struct TALER_AgeCommitmentHash);
mask = TALER_extensions_get_age_restriction_mask ();
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
@@ -590,7 +582,7 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
&mask,
age,
&seed,
- acp))
+ &ws->age_commitment_proof))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to generate age commitment for age %d at %s\n",
@@ -598,10 +590,8 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
label);
GNUNET_assert (0);
}
- TALER_age_commitment_hash (&acp->commitment,
- hac);
- ws->age_commitment_proof = acp;
- ws->h_age_commitment = hac;
+ TALER_age_commitment_hash (&ws->age_commitment_proof.commitment,
+ &ws->h_age_commitment);
}
ws->reserve_reference = reserve_reference;