Fix memory leak in GCM by adding gcm_free()
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 862328f..c6f52ff 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -295,6 +295,7 @@
static void gcm_ctx_free( void *ctx )
{
+ gcm_free( ctx );
polarssl_free( ctx );
}
diff --git a/library/gcm.c b/library/gcm.c
index 1dfc199..04e9d5b 100644
--- a/library/gcm.c
+++ b/library/gcm.c
@@ -406,6 +406,12 @@
return( 0 );
}
+void gcm_free( gcm_context *ctx )
+{
+ (void) cipher_free_ctx( &ctx->cipher_ctx );
+ memset( ctx, 0, sizeof( gcm_context ) );
+}
+
#if defined(POLARSSL_SELF_TEST)
#include <stdio.h>
@@ -672,6 +678,8 @@
return( 1 );
}
+ gcm_free( &ctx );
+
if( verbose != 0 )
printf( "passed\n" );
@@ -696,6 +704,8 @@
return( 1 );
}
+ gcm_free( &ctx );
+
if( verbose != 0 )
printf( "passed\n" );
@@ -759,6 +769,8 @@
return( 1 );
}
+ gcm_free( &ctx );
+
if( verbose != 0 )
printf( "passed\n" );
@@ -822,6 +834,8 @@
return( 1 );
}
+ gcm_free( &ctx );
+
if( verbose != 0 )
printf( "passed\n" );
@@ -834,6 +848,8 @@
return( 0 );
}
+
+
#endif
#endif