PBKDF2 implementation: refactor to avoid memleak
authorRichard Levitte <levitte@openssl.org>
Fri, 30 Aug 2019 13:11:08 +0000 (15:11 +0200)
committerPauli <paul.dale@oracle.com>
Fri, 6 Sep 2019 09:27:57 +0000 (19:27 +1000)
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9662)

providers/common/kdfs/pbkdf2.c

index 27bf28a89b18a5b7f954e85e2e64928ee48c1585..e60f0126f7c8296a4a974b7ced938a04ac2f643e 100644 (file)
@@ -75,11 +75,19 @@ static void *kdf_pbkdf2_new(void *provctx)
     return ctx;
 }
 
+static void kdf_pbkdf2_cleanup(KDF_PBKDF2 *ctx)
+{
+    EVP_MD_meth_free(ctx->md);
+    OPENSSL_free(ctx->salt);
+    OPENSSL_clear_free(ctx->pass, ctx->pass_len);
+    memset(ctx, 0, sizeof(*ctx));
+}
+
 static void kdf_pbkdf2_free(void *vctx)
 {
     KDF_PBKDF2 *ctx = (KDF_PBKDF2 *)vctx;
 
-    kdf_pbkdf2_reset(ctx);
+    kdf_pbkdf2_cleanup(ctx);
     OPENSSL_free(ctx);
 }
 
@@ -87,10 +95,7 @@ static void kdf_pbkdf2_reset(void *vctx)
 {
     KDF_PBKDF2 *ctx = (KDF_PBKDF2 *)vctx;
 
-    EVP_MD_meth_free(ctx->md);
-    OPENSSL_free(ctx->salt);
-    OPENSSL_clear_free(ctx->pass, ctx->pass_len);
-    memset(ctx, 0, sizeof(*ctx));
+    kdf_pbkdf2_cleanup(ctx);
     kdf_pbkdf2_init(ctx);
 }