From 617e32b9cfdb6fab572c40c348bc4ec05992b625 Mon Sep 17 00:00:00 2001 From: hasufell Date: Tue, 15 Apr 2014 14:15:41 +0200 Subject: [PATCH] RAND: fix memory leak pb_init() which is called by init_polynom_size() will call mp_init_copy() on chara which means that chara being a pointer itself is useless. We can clear it directly after it has been copied. --- src/rand.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rand.c b/src/rand.c index 7ec3f26..5b8985f 100644 --- a/src/rand.c +++ b/src/rand.c @@ -80,10 +80,11 @@ static mp_digit get_urnd_int_small(int *sign) */ pb_poly *ntru_get_urnd_poly_small(ntru_context *ctx) { - mp_int *chara = malloc(sizeof(mp_int)); - init_integer(chara); + mp_int chara; + init_integer(&chara); pb_poly *poly = malloc(sizeof(pb_poly)); - init_polynom_size(poly, chara, ctx->N); + init_polynom_size(poly, &chara, ctx->N); + mp_clear(&chara); for (int i = 0; i < ctx->N; i++) { int sign;