Skip to content

Commit

Permalink
crypto: avoid double free
Browse files Browse the repository at this point in the history
Coverity scan reported a free after use and I think its
right. Tweak to avoid double free.

Signed-off-by: Michael Dawson <mdawson@devrus.com>

PR-URL: #40380
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
mhdawson authored and targos committed Nov 4, 2021
1 parent 7b74638 commit de125a5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit de125a5

Please sign in to comment.