diff options
author | Richard Levitte <levitte@openssl.org> | 2019-08-30 15:11:08 +0200 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2019-09-06 19:27:57 +1000 |
commit | b1f15129933fdc98134ef2fcafb1ecea710f5920 (patch) | |
tree | d26b91c94fa87edcef2147b410424a2c0e09cf7e /providers | |
parent | df2f8af4cb3e19fe5a1ed41582d1659aa6c4ef50 (diff) |
PBKDF2 implementation: refactor to avoid memleak
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9662)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/common/kdfs/pbkdf2.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/providers/common/kdfs/pbkdf2.c b/providers/common/kdfs/pbkdf2.c index 27bf28a89b..e60f0126f7 100644 --- a/providers/common/kdfs/pbkdf2.c +++ b/providers/common/kdfs/pbkdf2.c @@ -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); } |