int engine_free_util(ENGINE *e, int locked)
{
    int i;

    if (e == NULL)
        return 1;
    if (locked)
        i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
    else
        i = --e->struct_ref;
    engine_ref_debug(e, 0, -1)
    if (i > 0)
        return 1;
#ifdef REF_CHECK
    if (i < 0) {
        fprintf(stderr, "ENGINE_free, bad structural reference count\n");
        abort();
    }
#endif
    /* Free up any dynamically allocated public key methods */
    engine_pkey_meths_free(e);
    engine_pkey_asn1_meths_free(e);
    /*
     * Give the ENGINE a chance to do any structural cleanup corresponding to
     * allocation it did in its constructor (eg. unload error strings)
     */
    if (e->destroy)
        e->destroy(e);
    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
    OPENSSL_free(e);
    return 1;
}