From 322daff844c1c479e12dc261e37d94adde3f5d93 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 11 Dec 2018 14:53:23 +0100 Subject: [PATCH] openssl: Make sure to release the functional ENGINE reference The functional reference created by ENGINE_init() was never released, only the structural one created by ENGINE_by_id(). The functional reference includes an implicit structural reference, which is also released by ENGINE_finish(). Closes strongswan/strongswan#119. --- src/libstrongswan/plugins/openssl/openssl_plugin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstrongswan/plugins/openssl/openssl_plugin.c b/src/libstrongswan/plugins/openssl/openssl_plugin.c index c5f1c5b14..cbeb6c3b7 100644 --- a/src/libstrongswan/plugins/openssl/openssl_plugin.c +++ b/src/libstrongswan/plugins/openssl/openssl_plugin.c @@ -436,21 +436,21 @@ static private_key_t *openssl_private_key_connect(key_type_t type, ENGINE_free(engine); return NULL; } + ENGINE_free(engine); if (!login(engine, keyid)) { DBG1(DBG_LIB, "login to engine '%s' failed", engine_id); - ENGINE_free(engine); + ENGINE_finish(engine); return NULL; } key = ENGINE_load_private_key(engine, keyname, NULL, NULL); + ENGINE_finish(engine); if (!key) { DBG1(DBG_LIB, "failed to load private key with ID '%s' from " "engine '%s'", keyname, engine_id); - ENGINE_free(engine); return NULL; } - ENGINE_free(engine); switch (EVP_PKEY_base_id(key)) {