diff options
author | Martin Willi <martin@revosec.ch> | 2011-04-21 10:48:16 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-04-21 10:48:16 +0200 |
commit | 3e2419ebe32de72d824864eb2e0e677a7c197af1 (patch) | |
tree | 2ee06332c69629a83bdca2de75daa057174535ef /src/libstrongswan | |
parent | 17ce69b47a1efd6234960cf7d1f50712aee61db5 (diff) | |
download | strongswan-3e2419ebe32de72d824864eb2e0e677a7c197af1.tar.bz2 strongswan-3e2419ebe32de72d824864eb2e0e677a7c197af1.tar.xz |
Use thread save settings alloc_str function where appropriate
Diffstat (limited to 'src/libstrongswan')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c | 21 | ||||
-rw-r--r-- | src/libstrongswan/plugins/pkcs11/pkcs11_manager.c | 9 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c index 0b607c386..39c28d3cd 100644 --- a/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c +++ b/src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c @@ -550,36 +550,34 @@ openssl_rsa_private_key_t *openssl_rsa_private_key_connect(key_type_t type, if (!engine_id) { - engine_id = lib->settings->get_str(lib->settings, + engine_id = lib->settings->alloc_str(lib->settings, "libstrongswan.plugins.openssl.engine_id", "pkcs11"); } engine = ENGINE_by_id(engine_id); if (!engine) { DBG2(DBG_LIB, "engine '%s' is not available", engine_id); - return NULL; + goto engine_failed; } if (!ENGINE_init(engine)) { DBG1(DBG_LIB, "failed to initialize engine '%s'", engine_id); - ENGINE_free(engine); - return NULL; + goto engine_failed; } if (!login(engine, keyid)) { DBG1(DBG_LIB, "login to engine '%s' failed", engine_id); - ENGINE_free(engine); - return NULL; + goto engine_failed; } key = ENGINE_load_private_key(engine, keyname, NULL, NULL); if (!key) { DBG1(DBG_LIB, "failed to load private key with ID '%s' from " "engine '%s'", keyname, engine_id); - ENGINE_free(engine); - return NULL; + goto engine_failed; } ENGINE_free(engine); + free(engine_id); this = create_empty(); this->rsa = EVP_PKEY_get1_RSA(key); @@ -594,5 +592,12 @@ openssl_rsa_private_key_t *openssl_rsa_private_key_connect(key_type_t type, #else /* OPENSSL_NO_ENGINE */ return NULL; #endif /* OPENSSL_NO_ENGINE */ +engine_failed: + if (engine) + { + ENGINE_free(engine); + } + free(engine_id); + return NULL; } diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c index 431cd6a2c..7579e0e2e 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c @@ -74,7 +74,8 @@ static void lib_entry_destroy(lib_entry_t *entry) { entry->job->cancel(entry->job); } - entry->lib->destroy(entry->lib); + DESTROY_IF(entry->lib); + free(entry->path); free(entry); } @@ -365,12 +366,12 @@ pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb, .this = this, ); - entry->path = lib->settings->get_str(lib->settings, + entry->path = lib->settings->alloc_str(lib->settings, "libstrongswan.plugins.pkcs11.modules.%s.path", NULL, module); if (!entry->path) { DBG1(DBG_CFG, "PKCS11 module '%s' lacks library path", module); - free(entry); + lib_entry_destroy(entry); continue; } entry->lib = pkcs11_library_create(module, entry->path, @@ -379,7 +380,7 @@ pkcs11_manager_t *pkcs11_manager_create(pkcs11_manager_token_event_t cb, FALSE, module)); if (!entry->lib) { - free(entry); + lib_entry_destroy(entry); continue; } this->libs->insert_last(this->libs, entry); |