aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/utils/gmp_helper.c
diff options
context:
space:
mode:
authorJan Hutter <jhutter@hsr.ch>2005-11-18 12:20:48 +0000
committerJan Hutter <jhutter@hsr.ch>2005-11-18 12:20:48 +0000
commitca0af3e80806a6251a02bec213fcbefb3be46f57 (patch)
treedd4dbce429fe123663b71bdb4f9389a1495635d9 /Source/charon/utils/gmp_helper.c
parent1186f05017fa4f8cad5c70b2c8396e354986a74c (diff)
downloadstrongswan-ca0af3e80806a6251a02bec213fcbefb3be46f57.tar.bz2
strongswan-ca0af3e80806a6251a02bec213fcbefb3be46f57.tar.xz
- memory leak fixed
Diffstat (limited to 'Source/charon/utils/gmp_helper.c')
-rw-r--r--Source/charon/utils/gmp_helper.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Source/charon/utils/gmp_helper.c b/Source/charon/utils/gmp_helper.c
index 9f3990c6d..c9417dae0 100644
--- a/Source/charon/utils/gmp_helper.c
+++ b/Source/charon/utils/gmp_helper.c
@@ -74,26 +74,28 @@ static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk
mpz_t temp1, temp2;
status_t status = SUCCESS;
int i;
+ chunk_t tmp_chunk;
- data->len = bytes;
- data->ptr = allocator_alloc(data->len);
+ tmp_chunk.len = bytes;
+ tmp_chunk.ptr = allocator_alloc(tmp_chunk.len);
- if (data->ptr == NULL)
+ if (tmp_chunk.ptr == NULL)
{
+ allocator_free_chunk(tmp_chunk);
return OUT_OF_RES;
}
/* free memory */
- memset(data->ptr,0,data->len);
+ memset(tmp_chunk.ptr,0,tmp_chunk.len);
mpz_init(temp1);
mpz_init(temp2);
mpz_set(temp1, *mpz_value);
- for (i = data->len-1; i >= 0; i--)
+ for (i = tmp_chunk.len-1; i >= 0; i--)
{
- data->ptr[i] = mpz_mdivmod_ui(temp2, NULL, temp1, 1 << 8);
+ tmp_chunk.ptr[i] = mpz_mdivmod_ui(temp2, NULL, temp1, 1 << 8);
mpz_set(temp1, temp2);
}
@@ -105,6 +107,11 @@ static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk
}
mpz_clear(temp1);
mpz_clear(temp2);
+ *data = tmp_chunk;
+ if (status != SUCCESS)
+ {
+ allocator_free_chunk(tmp_chunk);
+ }
return status;
}