static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
{
dynamic_data_ctx *c = OPENSSL_zalloc(sizeof(*c));
- int ret = 1;
+ int ret = 0;
if (c == NULL) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_MALLOC_FAILURE);
c->dirs = sk_OPENSSL_STRING_new_null();
if (c->dirs == NULL) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_MALLOC_FAILURE);
- OPENSSL_free(c);
- return 0;
+ goto end;
}
c->DYNAMIC_F1 = "v_check";
c->DYNAMIC_F2 = "bind_engine";
c->dir_load = 1;
- CRYPTO_THREAD_write_lock(global_engine_lock);
+ if (!CRYPTO_THREAD_write_lock(global_engine_lock))
+ goto end;
if ((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
dynamic_ex_data_idx))
== NULL) {
}
}
CRYPTO_THREAD_unlock(global_engine_lock);
+ ret = 1;
/*
* If we lost the race to set the context, c is non-NULL and *ctx is the
* context of the thread that won.
*/
- if (c)
+end:
+ if (c != NULL)
sk_OPENSSL_STRING_free(c->dirs);
OPENSSL_free(c);
return ret;
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_INDEX);
return NULL;
}
- CRYPTO_THREAD_write_lock(global_engine_lock);
+ if (!CRYPTO_THREAD_write_lock(global_engine_lock))
+ return NULL;
/* Avoid a race by checking again inside this lock */
if (dynamic_ex_data_idx < 0) {
/* Good, someone didn't beat us to it */