static int engine_list_remove(ENGINE *e) { ENGINE *iterator; if (e == NULL) { ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, ERR_R_PASSED_NULL_PARAMETER); return 0; } /* We need to check that e is in our linked list! */ iterator = engine_list_head; while (iterator && (iterator != e)) iterator = iterator->next; if (iterator == NULL) { ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, ENGINE_R_ENGINE_IS_NOT_IN_LIST); return 0; } /* un-link e from the chain. */ if (e->next) e->next->prev = e->prev; if (e->prev) e->prev->next = e->next; /* Correct our head/tail if necessary. */ if (engine_list_head == e) engine_list_head = e->next; if (engine_list_tail == e) engine_list_tail = e->prev; engine_free_util(e, 0); return 1; }
/* * Free a functional reference to a engine type. This version is only used * internally. */ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) { int to_return = 1; /* * Reduce the functional reference count here so if it's the terminating * case, we can release the lock safely and call the finish() handler * without risk of a race. We get a race if we leave the count until * after and something else is calling "finish" at the same time - * there's a chance that both threads will together take the count from 2 * to 0 without either calling finish(). */ e->funct_ref--; engine_ref_debug(e, 1, -1); if ((e->funct_ref == 0) && e->finish) { if (unlock_for_handlers) CRYPTO_THREAD_unlock(global_engine_lock); to_return = e->finish(e); if (unlock_for_handlers) CRYPTO_THREAD_write_lock(global_engine_lock); if (!to_return) return 0; } REF_ASSERT_ISNT(e->funct_ref < 0); /* Release the structural reference too */ if (!engine_free_util(e, 0)) { ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED); return 0; } return to_return; }
int ENGINE_free(ENGINE *e) { return engine_free_util(e, 1); }