Free EVP_MD_CTX in ima_calc_hash(). Also, remove legacy EVP_MD_CTX usage. Signed-off-by: Vitaly Chikunov <vt@xxxxxxxxxxxx> --- src/libimaevm.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libimaevm.c b/src/libimaevm.c index 6070614..dccb74c 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -322,12 +322,6 @@ int ima_calc_hash(const char *file, uint8_t *hash) EVP_MD_CTX *pctx; unsigned int mdlen; int err; -#if OPENSSL_VERSION_NUMBER < 0x10100000 - EVP_MD_CTX ctx; - pctx = &ctx; -#else - pctx = EVP_MD_CTX_new(); -#endif /* Need to know the file length */ err = lstat(file, &st); @@ -342,9 +336,11 @@ int ima_calc_hash(const char *file, uint8_t *hash) return 1; } + pctx = EVP_MD_CTX_new(); err = EVP_DigestInit(pctx, md); if (!err) { log_err("EVP_DigestInit() failed\n"); + EVP_MD_CTX_free(pctx); return 1; } @@ -364,18 +360,21 @@ int ima_calc_hash(const char *file, uint8_t *hash) break; default: log_errno("Unsupported file type"); + EVP_MD_CTX_free(pctx); return -1; } - if (err) + if (err) { + EVP_MD_CTX_free(pctx); return err; + } err = EVP_DigestFinal(pctx, hash, &mdlen); + EVP_MD_CTX_free(pctx); if (!err) { log_err("EVP_DigestFinal() failed\n"); return 1; } - return mdlen; } -- 2.11.0