diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-05 13:38:06 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2017-04-06 12:58:33 +0200 |
commit | 15b521cc8b12e3ad5f7812f65d71c4419d64863e (patch) | |
tree | 61e74c6a5b96e75cbdd044198760491a4e9ebbae | |
parent | 3c53f608c6470bc2b46851d1451c5c845d5cfc40 (diff) | |
download | gnutls-15b521cc8b12e3ad5f7812f65d71c4419d64863e.tar.gz |
gnutls-cli: better resource management in benchmark cmd
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r-- | src/benchmark-cipher.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/benchmark-cipher.c b/src/benchmark-cipher.c index ba1b929b9b..24d3665e8f 100644 --- a/src/benchmark-cipher.c +++ b/src/benchmark-cipher.c @@ -39,8 +39,8 @@ static void tls_log_func(int level, const char *str) static unsigned page_size = 4096; -#define ALLOC(x) x=malloc(step+64) -#define ALLOCM(x, mem) x=malloc(mem); assert(gnutls_rnd(GNUTLS_RND_NONCE, x, mem) >= 0) +#define ALLOC(x) {x=malloc(step+64);assert(x!=NULL);} +#define ALLOCM(x, mem) {x=malloc(mem); assert(x!=NULL); assert(gnutls_rnd(GNUTLS_RND_NONCE, x, mem) >= 0);} #define FREE(x) free(x) #define INC(orig, x, s) x+=page_size; if ((x+step) >= (((unsigned char*)orig) + MAX_MEM)) { x = orig; } @@ -114,10 +114,10 @@ static void cipher_mac_bench(int algo, int mac_algo, int size) gnutls_hmac_deinit(mac_ctx, NULL); stop_benchmark(&st, NULL, 1); - FREE(input); - FREE(output); leave: + FREE(input); + FREE(output); free(_key); free(_iv); } @@ -154,8 +154,10 @@ static void cipher_bench(int algo, int size, int aead) memset(_key, 0xf0, keysize); _iv = malloc(ivsize); - if (_iv == NULL) + if (_iv == NULL) { + free(_key); return; + } memset(_iv, 0xf0, ivsize); iv.data = _iv; |