From de125a556cd9b9a55035c4c7fe0f85552f6f7830 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 8 Oct 2021 18:24:40 -0400 Subject: [PATCH] crypto: avoid double free Coverity scan reported a free after use and I think its right. Tweak to avoid double free. Signed-off-by: Michael Dawson PR-URL: https://github.com/nodejs/node/pull/40380 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung Reviewed-By: Darshan Sen --- src/crypto/crypto_util.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index ac95612a0b1a85..9606c29097dfc0 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -550,9 +550,12 @@ struct EnginePointer { inline void reset(ENGINE* engine_ = nullptr, bool finish_on_exit_ = false) { if (engine != nullptr) { - if (finish_on_exit) - ENGINE_finish(engine); - ENGINE_free(engine); + if (finish_on_exit) { + // This also does the equivalent of ENGINE_free. + CHECK_EQ(ENGINE_finish(engine), 1); + } else { + CHECK_EQ(ENGINE_free(engine), 1); + } } engine = engine_; finish_on_exit = finish_on_exit_;