diff options
| 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 | 
| commit | 3024dc9fa54e8677b4816e56f8d215556a7d5561 (patch) | |
| tree | aaf2281e1c69327d4b91565d3b75c0a6fa36165a /src/util | |
| parent | 9d706a01a23e36e1c349d06e7a1be8bb44b7f0d5 (diff) | |
fix memory leaks reported by valgrind
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/age_restriction.c | 75 | 
1 files changed, 60 insertions, 15 deletions
| diff --git a/src/util/age_restriction.c b/src/util/age_restriction.c index 6f070229..eec0c834 100644 --- a/src/util/age_restriction.c +++ b/src/util/age_restriction.c @@ -464,6 +464,9 @@ void  TALER_age_proof_free (    struct TALER_AgeProof *proof)  { +  if (NULL == proof) +    return; +    if (NULL != proof->keys)    {      GNUNET_CRYPTO_zero_keys ( @@ -479,26 +482,71 @@ TALER_age_proof_free (  void  TALER_age_commitment_proof_free ( -  struct TALER_AgeCommitmentProof *cp) +  struct TALER_AgeCommitmentProof *acp)  { -  if (NULL != cp->proof.keys) +  if (NULL == acp) +    return; + +  if (NULL != acp->proof.keys)    {      GNUNET_CRYPTO_zero_keys ( -      cp->proof.keys, -      sizeof(*cp->proof.keys) * cp->proof.num); +      acp->proof.keys, +      sizeof(*acp->proof.keys) * acp->proof.num); -    GNUNET_free (cp->proof.keys); -    cp->proof.keys = NULL; +    GNUNET_free (acp->proof.keys); +    acp->proof.keys = NULL;    } -  if (NULL != cp->commitment.keys) +  if (NULL != acp->commitment.keys)    { -    GNUNET_free (cp->commitment.keys); -    cp->commitment.keys = NULL; +    GNUNET_free (acp->commitment.keys); +    acp->commitment.keys = NULL;    }  } +struct TALER_AgeCommitmentProof * +TALER_age_commitment_proof_duplicate ( +  const struct TALER_AgeCommitmentProof *acp) +{ +  struct TALER_AgeCommitmentProof *nacp; + +  GNUNET_assert (NULL != acp); +  GNUNET_assert (__builtin_popcount (acp->commitment.mask.bits) - 1 == +                 (int) acp->commitment.num); + +  nacp = GNUNET_new (struct TALER_AgeCommitmentProof); + +  TALER_age_commitment_proof_deep_copy (acp,nacp); +  return nacp; +} + + +void +TALER_age_commitment_proof_deep_copy ( +  const struct TALER_AgeCommitmentProof *acp, +  struct TALER_AgeCommitmentProof *nacp) +{ +  GNUNET_assert (NULL != acp); +  GNUNET_assert (__builtin_popcount (acp->commitment.mask.bits) - 1 == +                 (int) acp->commitment.num); + +  *nacp = *acp; +  nacp->commitment.keys = +    GNUNET_new_array (acp->commitment.num, +                      struct TALER_AgeCommitmentPublicKeyP); +  nacp->proof.keys = +    GNUNET_new_array (acp->proof.num, +                      struct TALER_AgeCommitmentPrivateKeyP); + +  for (size_t i = 0; i < acp->commitment.num; i++) +    nacp->commitment.keys[i] = acp->commitment.keys[i]; + +  for (size_t i = 0; i < acp->proof.num; i++) +    nacp->proof.keys[i] = acp->proof.keys[i]; +} + +  enum GNUNET_GenericReturnValue  TALER_JSON_parse_age_groups (const json_t *root,                               struct TALER_AgeMask *mask) @@ -571,19 +619,16 @@ TALER_parse_age_group_string (  } -char * +const char *  TALER_age_mask_to_string (    const struct TALER_AgeMask *mask)  { +  static char buf[256] = {0};    uint32_t bits = mask->bits;    unsigned int n = 0; -  char *buf = GNUNET_malloc (32 * 3); // max characters possible    char *pos = buf; -  if (NULL == buf) -  { -    return buf; -  } +  memset (buf, 0, sizeof(buf));    while (bits != 0)    { | 
