aboutsummaryrefslogtreecommitdiff
path: root/src/lib
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/lib
parent9d706a01a23e36e1c349d06e7a1be8bb44b7f0d5 (diff)
downloadexchange-3024dc9fa54e8677b4816e56f8d215556a7d5561.tar.xz
fix memory leaks reported by valgrind
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/exchange_api_link.c33
-rw-r--r--src/lib/exchange_api_melt.c18
-rw-r--r--src/lib/exchange_api_refresh_common.c25
-rw-r--r--src/lib/exchange_api_refresh_common.h5
-rw-r--r--src/lib/exchange_api_refreshes_reveal.c66
5 files changed, 79 insertions, 68 deletions
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c
index 04beeb296..86637683b 100644
--- a/src/lib/exchange_api_link.c
+++ b/src/lib/exchange_api_link.c
@@ -114,6 +114,7 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
struct TALER_TransferSecretP secret;
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
+ struct TALER_AgeCommitmentHash *pach = NULL;
/* parse reply */
if (GNUNET_OK !=
@@ -137,34 +138,35 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
&alg_values,
&bks);
- lci->age_commitment_proof = NULL;
- lci->h_age_commitment = NULL;
+ lci->has_age_commitment = false;
/* Derive the age commitment and calculate the hash */
if (NULL != lh->age_commitment_proof)
{
- lci->age_commitment_proof = GNUNET_new (struct TALER_AgeCommitmentProof);
- lci->h_age_commitment = GNUNET_new (struct TALER_AgeCommitmentHash);
GNUNET_assert (GNUNET_OK ==
TALER_age_commitment_derive (
lh->age_commitment_proof,
&secret.key,
- lci->age_commitment_proof));
+ &lci->age_commitment_proof));
TALER_age_commitment_hash (
- &(lci->age_commitment_proof->commitment),
- lci->h_age_commitment);
+ &lci->age_commitment_proof.commitment,
+ &lci->h_age_commitment);
+
+ lci->has_age_commitment = true;
+ pach = &lci->h_age_commitment;
}
if (GNUNET_OK !=
- TALER_planchet_prepare (&rpub,
- &alg_values,
- &bks,
- &lci->coin_priv,
- lci->h_age_commitment,
- &c_hash,
- &pd))
+ TALER_planchet_prepare (
+ &rpub,
+ &alg_values,
+ &bks,
+ &lci->coin_priv,
+ pach,
+ &c_hash,
+ &pd))
{
GNUNET_break (0);
GNUNET_JSON_parse_free (spec);
@@ -364,6 +366,8 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
{
TALER_denom_sig_free (&lcis[i].sig);
TALER_denom_pub_free (&lcis[i].pub);
+ if (lcis[i].has_age_commitment)
+ TALER_age_commitment_proof_free (&lcis[i].age_commitment_proof);
}
}
return ret;
@@ -513,6 +517,7 @@ TALER_EXCHANGE_link_cancel (struct TALER_EXCHANGE_LinkHandle *lh)
GNUNET_CURL_job_cancel (lh->job);
lh->job = NULL;
}
+
GNUNET_free (lh->url);
GNUNET_free (lh);
}
diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c
index f19f98c54..7fbd2114c 100644
--- a/src/lib/exchange_api_melt.c
+++ b/src/lib/exchange_api_melt.c
@@ -336,13 +336,14 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
}
TALER_denom_pub_hash (&mh->md.melted_coin.pub_key,
&h_denom_pub);
- TALER_wallet_melt_sign (&mh->md.melted_coin.melt_amount_with_fee,
- &mh->md.melted_coin.fee_melt,
- &mh->md.rc,
- &h_denom_pub,
- mh->md.melted_coin.h_age_commitment,
- &mh->md.melted_coin.coin_priv,
- &mh->coin_sig);
+ TALER_wallet_melt_sign (
+ &mh->md.melted_coin.melt_amount_with_fee,
+ &mh->md.melted_coin.fee_melt,
+ &mh->md.rc,
+ &h_denom_pub,
+ mh->md.melted_coin.h_age_commitment,
+ &mh->md.melted_coin.coin_priv,
+ &mh->coin_sig);
GNUNET_CRYPTO_eddsa_key_get_public (&mh->md.melted_coin.coin_priv.eddsa_priv,
&mh->coin_pub.eddsa_pub);
melt_obj = GNUNET_JSON_PACK (
@@ -357,7 +358,7 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
GNUNET_JSON_pack_data_auto ("rc",
&mh->md.rc),
GNUNET_JSON_pack_allow_null (
- mh->md.melted_coin.h_age_commitment
+ (NULL != mh->md.melted_coin.h_age_commitment)
? GNUNET_JSON_pack_data_auto ("age_commitment_hash",
mh->md.melted_coin.h_age_commitment)
: GNUNET_JSON_pack_string ("age_commitment_hash",
@@ -504,7 +505,6 @@ csr_cb (void *cls,
}
-/* FIXME: refactor this to use struct TALER_EXCHANGE_Handle */
struct TALER_EXCHANGE_MeltHandle *
TALER_EXCHANGE_melt (
struct GNUNET_CURL_Context *ctx,
diff --git a/src/lib/exchange_api_refresh_common.c b/src/lib/exchange_api_refresh_common.c
index 581e21152..04c580227 100644
--- a/src/lib/exchange_api_refresh_common.c
+++ b/src/lib/exchange_api_refresh_common.c
@@ -45,6 +45,11 @@ TALER_EXCHANGE_free_melt_data_ (struct MeltData *md)
struct FreshCoinData *fcd = &md->fcds[j];
TALER_denom_pub_free (&fcd->fresh_pk);
+ for (size_t i = 0; i < TALER_CNC_KAPPA; i++)
+ {
+ TALER_age_commitment_proof_free (fcd->age_commitment_proofs[i]);
+ GNUNET_free (fcd->age_commitment_proofs[i]);
+ }
}
GNUNET_free (md->fcds);
}
@@ -168,7 +173,8 @@ TALER_EXCHANGE_get_melt_data_ (
union TALER_DenominationBlindingKeyP *bks = &fcd->bks[i];
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
- struct TALER_AgeCommitmentHash *ach = NULL;
+ struct TALER_AgeCommitmentHash ach;
+ struct TALER_AgeCommitmentHash *pach = NULL;
TALER_transfer_secret_to_planchet_secret (&trans_sec,
j,
@@ -182,22 +188,21 @@ TALER_EXCHANGE_get_melt_data_ (
&alg_values[j],
bks);
- /* Handle age commitment, if present */
- if (NULL != md->melted_coin.age_commitment_proof)
+ if (NULL != rd->melt_age_commitment_proof)
{
- fcd->age_commitment_proof[i] = GNUNET_new (struct
- TALER_AgeCommitmentProof);
- ach = GNUNET_new (struct TALER_AgeCommitmentHash);
+ fcd->age_commitment_proofs[i] = GNUNET_new (struct
+ TALER_AgeCommitmentProof);
GNUNET_assert (GNUNET_OK ==
TALER_age_commitment_derive (
md->melted_coin.age_commitment_proof,
&trans_sec.key,
- fcd->age_commitment_proof[i]));
+ fcd->age_commitment_proofs[i]));
TALER_age_commitment_hash (
- &fcd->age_commitment_proof[i]->commitment,
- ach);
+ &fcd->age_commitment_proofs[i]->commitment,
+ &ach);
+ pach = &ach;
}
if (TALER_DENOMINATION_CS == alg_values[j].cipher)
@@ -208,7 +213,7 @@ TALER_EXCHANGE_get_melt_data_ (
&alg_values[j],
bks,
coin_priv,
- ach,
+ pach,
&c_hash,
&pd))
{
diff --git a/src/lib/exchange_api_refresh_common.h b/src/lib/exchange_api_refresh_common.h
index c06824fec..0cb80f17e 100644
--- a/src/lib/exchange_api_refresh_common.h
+++ b/src/lib/exchange_api_refresh_common.h
@@ -101,10 +101,9 @@ struct FreshCoinData
/**
* Arrays of age commitments and proofs to be created, one for each
- * cut-and-choose dimension. The entries in each list might be NULL and
- * indicate no age commitment/restriction on the particular coin.
+ * cut-and-choose dimension. NULL if age restriction is not applicable.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof[TALER_CNC_KAPPA];
+ struct TALER_AgeCommitmentProof *age_commitment_proofs[TALER_CNC_KAPPA];
/**
* Blinding key secrets for the coins, depending on the
diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c
index 291c3be12..3360accd9 100644
--- a/src/lib/exchange_api_refreshes_reveal.c
+++ b/src/lib/exchange_api_refreshes_reveal.c
@@ -125,8 +125,7 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
}
for (unsigned int i = 0; i<rrh->md.num_fresh_coins; i++)
{
- struct TALER_EXCHANGE_RevealedCoinInfo *rci =
- &rcis[i];
+ struct TALER_EXCHANGE_RevealedCoinInfo *rci = &rcis[i];
const struct FreshCoinData *fcd = &rrh->md.fcds[i];
const struct TALER_DenominationPublicKey *pk;
json_t *jsonai;
@@ -140,25 +139,25 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
};
struct TALER_FreshCoin coin;
union TALER_DenominationBlindingKeyP bks;
+ const struct TALER_AgeCommitmentHash *pach = NULL;
rci->ps = fcd->ps[rrh->noreveal_index];
rci->bks = fcd->bks[rrh->noreveal_index];
- rci->age_commitment_proof = fcd->age_commitment_proof[rrh->noreveal_index];
- rci->h_age_commitment = NULL;
+ rci->age_commitment_proof = NULL;
+
pk = &fcd->fresh_pk;
jsonai = json_array_get (jsona, i);
GNUNET_assert (NULL != jsonai);
- GNUNET_assert (
- (NULL != rrh->md.melted_coin.age_commitment_proof) ==
- (NULL != rci->age_commitment_proof));
- if (NULL != rci->age_commitment_proof)
+ if (NULL != rrh->md.melted_coin.age_commitment_proof)
{
- rci->h_age_commitment = GNUNET_new (struct TALER_AgeCommitmentHash);
- TALER_age_commitment_hash (
- &rci->age_commitment_proof->commitment,
- rci->h_age_commitment);
+ rci->age_commitment_proof =
+ fcd->age_commitment_proofs[rrh->noreveal_index];
+
+ TALER_age_commitment_hash (&rci->age_commitment_proof->commitment,
+ &rci->h_age_commitment);
+ pach = &rci->h_age_commitment;
}
if (GNUNET_OK !=
@@ -180,18 +179,20 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
hence recomputing it here... */
GNUNET_CRYPTO_eddsa_key_get_public (&rci->coin_priv.eddsa_priv,
&coin_pub.eddsa_pub);
- TALER_coin_pub_hash (&coin_pub,
- rci->h_age_commitment,
- &coin_hash);
+ TALER_coin_pub_hash (
+ &coin_pub,
+ pach,
+ &coin_hash);
if (GNUNET_OK !=
- TALER_planchet_to_coin (pk,
- &blind_sig,
- &bks,
- &rci->coin_priv,
- rci->h_age_commitment,
- &coin_hash,
- &rrh->alg_values[i],
- &coin))
+ TALER_planchet_to_coin (
+ pk,
+ &blind_sig,
+ &bks,
+ &rci->coin_priv,
+ pach,
+ &coin_hash,
+ &rrh->alg_values[i],
+ &coin))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -257,7 +258,10 @@ handle_refresh_reveal_finished (void *cls,
rrh->reveal_cb = NULL;
}
for (unsigned int i = 0; i<rrh->md.num_fresh_coins; i++)
+ {
TALER_denom_sig_free (&rcis[i].sig);
+ TALER_age_commitment_proof_free (rcis[i].age_commitment_proof);
+ }
TALER_EXCHANGE_refreshes_reveal_cancel (rrh);
return;
}
@@ -303,7 +307,6 @@ handle_refresh_reveal_finished (void *cls,
}
-/* FIXME: refactor this to use struct TALER_EXCHANGE_Handle */
struct TALER_EXCHANGE_RefreshesRevealHandle *
TALER_EXCHANGE_refreshes_reveal (
struct GNUNET_CURL_Context *ctx,
@@ -408,20 +411,19 @@ TALER_EXCHANGE_refreshes_reveal (
}
/* build array of old age commitment, if applicable */
- GNUNET_assert ((NULL == rd->melt_age_commitment_proof) ==
- (NULL == rd->melt_h_age_commitment));
if (NULL != rd->melt_age_commitment_proof)
{
+ GNUNET_assert (NULL != rd->melt_h_age_commitment);
GNUNET_assert (NULL != (old_age_commitment = json_array ()));
for (size_t i = 0; i < rd->melt_age_commitment_proof->commitment.num; i++)
{
- GNUNET_assert (0 ==
- json_array_append_new (
- old_age_commitment,
- GNUNET_JSON_from_data_auto (
- &rd->melt_age_commitment_proof->
- commitment.keys[i])));
+ enum GNUNET_GenericReturnValue ret;
+ ret = json_array_append_new (
+ old_age_commitment,
+ GNUNET_JSON_from_data_auto (
+ &rd->melt_age_commitment_proof->commitment.keys[i]));
+ GNUNET_assert (0 == ret);
}
}