void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
    unsigned long hash;
    OPENSSL_LH_NODE *nn, **rn;
    void *ret;
    lh->error = 0;
    rn = getrn(lh, data, &hash);
    if (*rn == NULL) {
        lh->num_no_delete++;
        return (NULL);
    } else {
        nn = *rn;
        *rn = nn->next;
        ret = nn->data;
        OPENSSL_free(nn);
        lh->num_delete++;
    }
    lh->num_items--;
    if ((lh->num_nodes > MIN_NODES) &&
        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
        contract(lh);
    return (ret);
}
['int s_time_main(int argc, char **argv)\n{\n    char buf[1024 * 8];\n    SSL *scon = NULL;\n    SSL_CTX *ctx = NULL;\n    const SSL_METHOD *meth = NULL;\n    char *CApath = NULL, *CAfile = NULL, *cipher = NULL, *www_path = NULL;\n    char *host = SSL_CONNECT_NAME, *certfile = NULL, *keyfile = NULL, *prog;\n    double totalTime = 0.0;\n    int noCApath = 0, noCAfile = 0;\n    int maxtime = SECONDS, nConn = 0, perform = 3, ret = 1, i, st_bugs =\n        0, ver;\n    long bytes_read = 0, finishtime = 0;\n    OPTION_CHOICE o;\n    int max_version = 0;\n    meth = TLS_client_method();\n    verify_depth = 0;\n    verify_error = X509_V_OK;\n    prog = opt_init(argc, argv, s_time_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(s_time_options);\n            ret = 0;\n            goto end;\n        case OPT_CONNECT:\n            host = opt_arg();\n            break;\n        case OPT_REUSE:\n            perform = 2;\n            break;\n        case OPT_NEW:\n            perform = 1;\n            break;\n        case OPT_VERIFY:\n            if (!opt_int(opt_arg(), &verify_depth))\n                goto opthelp;\n            BIO_printf(bio_err, "%s: verify depth is %d\\n",\n                       prog, verify_depth);\n            break;\n        case OPT_CERT:\n            certfile = opt_arg();\n            break;\n        case OPT_KEY:\n            keyfile = opt_arg();\n            break;\n        case OPT_CAPATH:\n            CApath = opt_arg();\n            break;\n        case OPT_CAFILE:\n            CAfile = opt_arg();\n            break;\n        case OPT_NOCAPATH:\n            noCApath = 1;\n            break;\n        case OPT_NOCAFILE:\n            noCAfile = 1;\n            break;\n        case OPT_CIPHER:\n            cipher = opt_arg();\n            break;\n        case OPT_BUGS:\n            st_bugs = 1;\n            break;\n        case OPT_TIME:\n            if (!opt_int(opt_arg(), &maxtime))\n                goto opthelp;\n            break;\n        case OPT_WWW:\n            www_path = opt_arg();\n            if (strlen(www_path) > MYBUFSIZ - 100) {\n                BIO_printf(bio_err, "%s: -www option too long\\n", prog);\n                goto end;\n            }\n            break;\n        case OPT_SSL3:\n            max_version = SSL3_VERSION;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    if (argc != 0)\n        goto opthelp;\n    if (cipher == NULL)\n        cipher = getenv("SSL_CIPHER");\n    if (cipher == NULL) {\n        BIO_printf(bio_err, "No CIPHER specified\\n");\n        goto end;\n    }\n    if ((ctx = SSL_CTX_new(meth)) == NULL)\n        goto end;\n    SSL_CTX_set_quiet_shutdown(ctx, 1);\n    if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)\n        goto end;\n    if (st_bugs)\n        SSL_CTX_set_options(ctx, SSL_OP_ALL);\n    if (!SSL_CTX_set_cipher_list(ctx, cipher))\n        goto end;\n    if (!set_cert_stuff(ctx, certfile, keyfile))\n        goto end;\n    if (!ctx_set_verify_locations(ctx, CAfile, CApath, noCAfile, noCApath)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (!(perform & 1))\n        goto next;\n    printf("Collecting connection statistics for %d seconds\\n", maxtime);\n    bytes_read = 0;\n    finishtime = (long)time(NULL) + maxtime;\n    tm_Time_F(START);\n    for (;;) {\n        if (finishtime < (long)time(NULL))\n            break;\n        if ((scon = doConnection(NULL, host, ctx)) == NULL)\n            goto end;\n        if (www_path != NULL) {\n            BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n",\n                         www_path);\n            if (SSL_write(scon, buf, strlen(buf)) <= 0)\n                goto end;\n            while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)\n                bytes_read += i;\n        }\n#ifdef NO_SHUTDOWN\n        SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n        SSL_shutdown(scon);\n#endif\n        BIO_closesocket(SSL_get_fd(scon));\n        nConn += 1;\n        if (SSL_session_reused(scon))\n            ver = \'r\';\n        else {\n            ver = SSL_version(scon);\n            if (ver == TLS1_VERSION)\n                ver = \'t\';\n            else if (ver == SSL3_VERSION)\n                ver = \'3\';\n            else\n                ver = \'*\';\n        }\n        fputc(ver, stdout);\n        fflush(stdout);\n        SSL_free(scon);\n        scon = NULL;\n    }\n    totalTime += tm_Time_F(STOP);\n    i = (int)((long)time(NULL) - finishtime + maxtime);\n    printf\n        ("\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n",\n         nConn, totalTime, ((double)nConn / totalTime), bytes_read);\n    printf\n        ("%d connections in %ld real seconds, %ld bytes read per connection\\n",\n         nConn, (long)time(NULL) - finishtime + maxtime, bytes_read / nConn);\n next:\n    if (!(perform & 2))\n        goto end;\n    printf("\\n\\nNow timing with session id reuse.\\n");\n    if ((scon = doConnection(NULL, host, ctx)) == NULL) {\n        BIO_printf(bio_err, "Unable to get connection\\n");\n        goto end;\n    }\n    if (www_path != NULL) {\n        BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n", www_path);\n        if (SSL_write(scon, buf, strlen(buf)) <= 0)\n            goto end;\n        while (SSL_read(scon, buf, sizeof(buf)) > 0)\n            continue;\n    }\n#ifdef NO_SHUTDOWN\n    SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n    SSL_shutdown(scon);\n#endif\n    BIO_closesocket(SSL_get_fd(scon));\n    nConn = 0;\n    totalTime = 0.0;\n    finishtime = (long)time(NULL) + maxtime;\n    printf("starting\\n");\n    bytes_read = 0;\n    tm_Time_F(START);\n    for (;;) {\n        if (finishtime < (long)time(NULL))\n            break;\n        if ((doConnection(scon, host, ctx)) == NULL)\n            goto end;\n        if (www_path) {\n            BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n",\n                         www_path);\n            if (SSL_write(scon, buf, strlen(buf)) <= 0)\n                goto end;\n            while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)\n                bytes_read += i;\n        }\n#ifdef NO_SHUTDOWN\n        SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n        SSL_shutdown(scon);\n#endif\n        BIO_closesocket(SSL_get_fd(scon));\n        nConn += 1;\n        if (SSL_session_reused(scon))\n            ver = \'r\';\n        else {\n            ver = SSL_version(scon);\n            if (ver == TLS1_VERSION)\n                ver = \'t\';\n            else if (ver == SSL3_VERSION)\n                ver = \'3\';\n            else\n                ver = \'*\';\n        }\n        fputc(ver, stdout);\n        fflush(stdout);\n    }\n    totalTime += tm_Time_F(STOP);\n    printf\n        ("\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n",\n         nConn, totalTime, ((double)nConn / totalTime), bytes_read);\n    printf\n        ("%d connections in %ld real seconds, %ld bytes read per connection\\n",\n         nConn, (long)time(NULL) - finishtime + maxtime, bytes_read / nConn);\n    ret = 0;\n end:\n    SSL_free(scon);\n    SSL_CTX_free(ctx);\n    return (ret);\n}', 'static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx)\n{\n    BIO *conn;\n    SSL *serverCon;\n    int width, i;\n    fd_set readfds;\n    if ((conn = BIO_new(BIO_s_connect())) == NULL)\n        return (NULL);\n    BIO_set_conn_hostname(conn, host);\n    if (scon == NULL)\n        serverCon = SSL_new(ctx);\n    else {\n        serverCon = scon;\n        SSL_set_connect_state(serverCon);\n    }\n    SSL_set_bio(serverCon, conn, conn);\n    for (;;) {\n        i = SSL_connect(serverCon);\n        if (BIO_sock_should_retry(i)) {\n            BIO_printf(bio_err, "DELAY\\n");\n            i = SSL_get_fd(serverCon);\n            width = i + 1;\n            FD_ZERO(&readfds);\n            openssl_fdset(i, &readfds);\n            select(width, (void *)&readfds, NULL, NULL, NULL);\n            continue;\n        }\n        break;\n    }\n    if (i <= 0) {\n        BIO_printf(bio_err, "ERROR\\n");\n        if (verify_error != X509_V_OK)\n            BIO_printf(bio_err, "verify error:%s\\n",\n                       X509_verify_cert_error_string(verify_error));\n        else\n            ERR_print_errors(bio_err);\n        if (scon == NULL)\n            SSL_free(serverCon);\n        return NULL;\n    }\n    return serverCon;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n    SSL *s;\n    if (ctx == NULL) {\n        SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n        return (NULL);\n    }\n    if (ctx->method == NULL) {\n        SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n        return (NULL);\n    }\n    s = OPENSSL_zalloc(sizeof(*s));\n    if (s == NULL)\n        goto err;\n    s->lock = CRYPTO_THREAD_lock_new();\n    if (s->lock == NULL) {\n        SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n        OPENSSL_free(s);\n        return NULL;\n    }\n    RECORD_LAYER_init(&s->rlayer, s);\n    s->options = ctx->options;\n    s->min_proto_version = ctx->min_proto_version;\n    s->max_proto_version = ctx->max_proto_version;\n    s->mode = ctx->mode;\n    s->max_cert_list = ctx->max_cert_list;\n    s->references = 1;\n    s->cert = ssl_cert_dup(ctx->cert);\n    if (s->cert == NULL)\n        goto err;\n    RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n    s->msg_callback = ctx->msg_callback;\n    s->msg_callback_arg = ctx->msg_callback_arg;\n    s->verify_mode = ctx->verify_mode;\n    s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n    s->sid_ctx_length = ctx->sid_ctx_length;\n    OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n    memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n    s->verify_callback = ctx->default_verify_callback;\n    s->generate_session_id = ctx->generate_session_id;\n    s->param = X509_VERIFY_PARAM_new();\n    if (s->param == NULL)\n        goto err;\n    X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n    s->quiet_shutdown = ctx->quiet_shutdown;\n    s->max_send_fragment = ctx->max_send_fragment;\n    s->split_send_fragment = ctx->split_send_fragment;\n    s->max_pipelines = ctx->max_pipelines;\n    if (s->max_pipelines > 1)\n        RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n    if (ctx->default_read_buf_len > 0)\n        SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n    SSL_CTX_up_ref(ctx);\n    s->ctx = ctx;\n    s->tlsext_debug_cb = 0;\n    s->tlsext_debug_arg = NULL;\n    s->tlsext_ticket_expected = 0;\n    s->tlsext_status_type = ctx->tlsext_status_type;\n    s->tlsext_status_expected = 0;\n    s->tlsext_ocsp_ids = NULL;\n    s->tlsext_ocsp_exts = NULL;\n    s->tlsext_ocsp_resp = NULL;\n    s->tlsext_ocsp_resplen = -1;\n    SSL_CTX_up_ref(ctx);\n    s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n    if (ctx->tlsext_ecpointformatlist) {\n        s->tlsext_ecpointformatlist =\n            OPENSSL_memdup(ctx->tlsext_ecpointformatlist,\n                           ctx->tlsext_ecpointformatlist_length);\n        if (!s->tlsext_ecpointformatlist)\n            goto err;\n        s->tlsext_ecpointformatlist_length =\n            ctx->tlsext_ecpointformatlist_length;\n    }\n    if (ctx->tlsext_ellipticcurvelist) {\n        s->tlsext_ellipticcurvelist =\n            OPENSSL_memdup(ctx->tlsext_ellipticcurvelist,\n                           ctx->tlsext_ellipticcurvelist_length);\n        if (!s->tlsext_ellipticcurvelist)\n            goto err;\n        s->tlsext_ellipticcurvelist_length =\n            ctx->tlsext_ellipticcurvelist_length;\n    }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n    s->next_proto_negotiated = NULL;\n# endif\n    if (s->ctx->alpn_client_proto_list) {\n        s->alpn_client_proto_list =\n            OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n        if (s->alpn_client_proto_list == NULL)\n            goto err;\n        memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n               s->ctx->alpn_client_proto_list_len);\n        s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n    }\n    s->verified_chain = NULL;\n    s->verify_result = X509_V_OK;\n    s->default_passwd_callback = ctx->default_passwd_callback;\n    s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n    s->method = ctx->method;\n    if (!s->method->ssl_new(s))\n        goto err;\n    s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n    if (!SSL_clear(s))\n        goto err;\n    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n        goto err;\n#ifndef OPENSSL_NO_PSK\n    s->psk_client_callback = ctx->psk_client_callback;\n    s->psk_server_callback = ctx->psk_server_callback;\n#endif\n    s->job = NULL;\n#ifndef OPENSSL_NO_CT\n    if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n            ctx->ct_validation_callback_arg))\n        goto err;\n#endif\n    return s;\n err:\n    SSL_free(s);\n    SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n    return NULL;\n}', 'void SSL_free(SSL *s)\n{\n    int i;\n    if (s == NULL)\n        return;\n    CRYPTO_atomic_add(&s->references, -1, &i, s->lock);\n    REF_PRINT_COUNT("SSL", s);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(s->param);\n    dane_final(&s->dane);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n    if (s->bbio != NULL) {\n        if (s->bbio == s->wbio) {\n            s->wbio = BIO_pop(s->wbio);\n        }\n        BIO_free(s->bbio);\n        s->bbio = NULL;\n    }\n    if (s->wbio != s->rbio)\n        BIO_free_all(s->wbio);\n    BIO_free_all(s->rbio);\n    BUF_MEM_free(s->init_buf);\n    sk_SSL_CIPHER_free(s->cipher_list);\n    sk_SSL_CIPHER_free(s->cipher_list_by_id);\n    if (s->session != NULL) {\n        ssl_clear_bad_session(s);\n        SSL_SESSION_free(s->session);\n    }\n    clear_ciphers(s);\n    ssl_cert_free(s->cert);\n    OPENSSL_free(s->tlsext_hostname);\n    SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(s->tlsext_ecpointformatlist);\n    OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n    sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n    sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n    SCT_LIST_free(s->scts);\n    OPENSSL_free(s->tlsext_scts);\n#endif\n    OPENSSL_free(s->tlsext_ocsp_resp);\n    OPENSSL_free(s->alpn_client_proto_list);\n    sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);\n    sk_X509_pop_free(s->verified_chain, X509_free);\n    if (s->method != NULL)\n        s->method->ssl_free(s);\n    RECORD_LAYER_release(&s->rlayer);\n    SSL_CTX_free(s->ctx);\n    ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    OPENSSL_free(s->next_proto_negotiated);\n#endif\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n    CRYPTO_THREAD_lock_free(s->lock);\n    OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n    if ((s->session != NULL) &&\n        !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n        !(SSL_in_init(s) || SSL_in_before(s))) {\n        SSL_CTX_remove_session(s->session_ctx, s->session);\n        return (1);\n    } else\n        return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n    return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n    SSL_SESSION *r;\n    int ret = 0;\n    if ((c != NULL) && (c->session_id_length != 0)) {\n        if (lck)\n            CRYPTO_THREAD_write_lock(ctx->lock);\n        if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n            ret = 1;\n            r = lh_SSL_SESSION_delete(ctx->sessions, c);\n            SSL_SESSION_list_remove(ctx, c);\n        }\n        if (lck)\n            CRYPTO_THREAD_unlock(ctx->lock);\n        if (ret) {\n            r->not_resumable = 1;\n            if (ctx->remove_session_cb != NULL)\n                ctx->remove_session_cb(ctx, r);\n            SSL_SESSION_free(r);\n        }\n    } else\n        ret = 0;\n    return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        lh->num_no_delete++;\n        return (NULL);\n    } else {\n        nn = *rn;\n        *rn = nn->next;\n        ret = nn->data;\n        OPENSSL_free(nn);\n        lh->num_delete++;\n    }\n    lh->num_items--;\n    if ((lh->num_nodes > MIN_NODES) &&\n        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n        contract(lh);\n    return (ret);\n}']