From 43b08574a6d6e138e2bf707a69d1f499b126e19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 27 May 2015 17:23:30 +0200 Subject: [PATCH] Avoid memory leak with repeated [gc]ccm_setkey() --- library/ccm.c | 2 ++ library/gcm.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/library/ccm.c b/library/ccm.c index 75de8cb5b9..aa2d6754b4 100644 --- a/library/ccm.c +++ b/library/ccm.c @@ -81,6 +81,8 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, if( cipher_info->block_size != 16 ) return( MBEDTLS_ERR_CCM_BAD_INPUT ); + mbedtls_cipher_free( &ctx->cipher_ctx ); + if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) return( ret ); diff --git a/library/gcm.c b/library/gcm.c index 79d433a175..a347c06779 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -174,6 +174,8 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, if( cipher_info->block_size != 16 ) return( MBEDTLS_ERR_GCM_BAD_INPUT ); + mbedtls_cipher_free( &ctx->cipher_ctx ); + if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) return( ret );