From 0c4eb06e26dd781ba1717a85746598ecd3017c1a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 7 Oct 2015 12:34:45 +1030 Subject: [PATCH] test_onion: remove gratuitous dynamic alloc, cleanup on exit. We skipped freeing the context in the too-many-hops case. Signed-off-by: Rusty Russell --- test/test_onion.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/test_onion.c b/test/test_onion.c index fa643626d..21b9aafe4 100644 --- a/test/test_onion.c +++ b/test/test_onion.c @@ -381,23 +381,23 @@ bool create_onion(const secp256k1_pubkey pubkey[], struct onion *onion) { int i; - struct seckey *seckeys = tal_arr(NULL, struct seckey, num); - struct onion_pubkey *pubkeys = tal_arr(seckeys, struct onion_pubkey, num); - struct enckey *enckeys = tal_arr(seckeys, struct enckey, num); - struct hmackey *hmackeys = tal_arr(seckeys, struct hmackey, num); - struct iv *ivs = tal_arr(seckeys, struct iv, num); - struct iv *pad_ivs = tal_arr(seckeys, struct iv, num); - HMAC_CTX *padding_hmac = tal_arr(seckeys, HMAC_CTX, num); - struct hop *padding = tal_arr(seckeys, struct hop, num); + struct seckey seckeys[MAX_HOPS]; + struct onion_pubkey pubkeys[MAX_HOPS]; + struct enckey enckeys[MAX_HOPS]; + struct hmackey hmackeys[MAX_HOPS]; + struct iv ivs[MAX_HOPS]; + struct iv pad_ivs[MAX_HOPS]; + HMAC_CTX padding_hmac[MAX_HOPS]; + struct hop padding[MAX_HOPS]; size_t junk_hops; - secp256k1_context *ctx; + secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); bool ok = false; if (num > MAX_HOPS) goto fail; - ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); - + /* FIXME: I think it would be safe to reuse a single disposable key + * here? */ /* First generate all the keys. */ for (i = 0; i < num; i++) { unsigned char secret[32]; @@ -485,7 +485,6 @@ bool create_onion(const secp256k1_pubkey pubkey[], ok = true; fail: - tal_free(seckeys); secp256k1_context_destroy(ctx); return ok; }