apps/s_server.c:2656: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `SSL_free`.
Showing all 16 steps of the trace


apps/s_server.c:2205:11: Call
2203.       }
2204.   
2205.       con = SSL_new(ctx);
                  ^
2206.       if (con == NULL) {
2207.           ret = -1;

ssl/ssl_lib.c:610:1: Parameter `ctx->sessions->num_nodes`
  608.   }
  609.   
  610. > SSL *SSL_new(SSL_CTX *ctx)
  611.   {
  612.       SSL *s;

apps/s_server.c:2656:9: Call
2654.           BIO_printf(bio_s_out, "shutting down SSL\n");
2655.           SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
2656.           SSL_free(con);
                ^
2657.       }
2658.       BIO_printf(bio_s_out, "CONNECTION CLOSED\n");

ssl/ssl_lib.c:1073:1: Parameter `s->ctx->sessions->num_nodes`
  1071.   }
  1072.   
  1073. > void SSL_free(SSL *s)
  1074.   {
  1075.       int i;

ssl/ssl_lib.c:1143:5: Call
  1141.       RECORD_LAYER_release(&s->rlayer);
  1142.   
  1143.       SSL_CTX_free(s->ctx);
              ^
  1144.   
  1145.       ASYNC_WAIT_CTX_free(s->waitctx);

ssl/ssl_lib.c:2914:1: Parameter `a->sessions->num_nodes`
    2912.   }
    2913.   
    2914. > void SSL_CTX_free(SSL_CTX *a)
    2915.   {
    2916.       int i;

ssl/ssl_lib.c:2940:9: Call
    2938.        */
    2939.       if (a->sessions != NULL)
    2940.           SSL_CTX_flush_sessions(a, 0);
                    ^
    2941.   
    2942.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);

ssl/ssl_sess.c:1089:1: Parameter `s->sessions->num_nodes`
      1087.   IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
      1088.   
      1089. > void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
      1090.   {
      1091.       unsigned long i;

ssl/ssl_sess.c:1102:5: Call
      1100.       i = lh_SSL_SESSION_get_down_load(s->sessions);
      1101.       lh_SSL_SESSION_set_down_load(s->sessions, 0);
      1102.       lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
                  ^
      1103.       lh_SSL_SESSION_set_down_load(s->sessions, i);
      1104.       CRYPTO_THREAD_unlock(s->lock);

ssl/ssl_sess.c:1087:1: Parameter `lh->num_nodes`
        1085.   }
        1086.   
        1087. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1088.   
        1089.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

ssl/ssl_sess.c:1087:1: Call
        1085.   }
        1086.   
        1087. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1088.   
        1089.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

crypto/lhash/lhash.c:181:1: Parameter `lh->num_nodes`
          179.   }
          180.   
          181. > void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
          182.   {
          183.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);

crypto/lhash/lhash.c:183:5: Call
          181.   void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
          182.   {
          183.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);
                     ^
          184.   }
          185.   

crypto/lhash/lhash.c:149:1: <LHS trace>
147.   }
148.   
149. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
150.                             OPENSSL_LH_DOALL_FUNC func,
151.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:149:1: Parameter `lh->num_nodes`
            147.   }
            148.   
            149. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
            150.                             OPENSSL_LH_DOALL_FUNC func,
            151.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:163:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `SSL_free` 
            161.        * memory leaks otherwise
            162.        */
            163.       for (i = lh->num_nodes - 1; i >= 0; i--) {
                            ^
            164.           a = lh->b[i];
            165.           while (a != NULL) {

static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
                          OPENSSL_LH_DOALL_FUNC func,
                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
    int i;
    OPENSSL_LH_NODE *a, *n;
    if (lh == NULL)
        return;
    for (i = lh->num_nodes - 1; i >= 0; i--) {
        a = lh->b[i];
        while (a != NULL) {
            n = a->next;
            if (use_arg)
                func_arg(a->data, arg);
            else
                func(a->data);
            a = n;
        }
    }
}
['static int sv_body(int s, int stype, int prot, unsigned char *context)\n{\n    char *buf = NULL;\n    fd_set readfds;\n    int ret = 1, width;\n    int k, i;\n    unsigned long l;\n    SSL *con = NULL;\n    BIO *sbio;\n    struct timeval timeout;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n    struct timeval tv;\n#else\n    struct timeval *timeoutp;\n#endif\n#ifndef OPENSSL_NO_DTLS\n# ifndef OPENSSL_NO_SCTP\n    int isdtls = (stype == SOCK_DGRAM || prot == IPPROTO_SCTP);\n# else\n    int isdtls = (stype == SOCK_DGRAM);\n# endif\n#endif\n    buf = app_malloc(bufsize, "server buffer");\n    if (s_nbio) {\n        if (!BIO_socket_nbio(s, 1))\n            ERR_print_errors(bio_err);\n        else if (!s_quiet)\n            BIO_printf(bio_err, "Turned on non blocking io\\n");\n    }\n    con = SSL_new(ctx);\n    if (con == NULL) {\n        ret = -1;\n        goto err;\n    }\n    if (s_tlsextdebug) {\n        SSL_set_tlsext_debug_callback(con, tlsext_cb);\n        SSL_set_tlsext_debug_arg(con, bio_s_out);\n    }\n    if (context != NULL\n        && !SSL_set_session_id_context(con, context,\n                                       strlen((char *)context))) {\n        BIO_printf(bio_err, "Error setting session id context\\n");\n        ret = -1;\n        goto err;\n    }\n    if (!SSL_clear(con)) {\n        BIO_printf(bio_err, "Error clearing SSL connection\\n");\n        ret = -1;\n        goto err;\n    }\n#ifndef OPENSSL_NO_DTLS\n    if (isdtls) {\n# ifndef OPENSSL_NO_SCTP\n        if (prot == IPPROTO_SCTP)\n            sbio = BIO_new_dgram_sctp(s, BIO_NOCLOSE);\n        else\n# endif\n            sbio = BIO_new_dgram(s, BIO_NOCLOSE);\n        if (enable_timeouts) {\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_RCV_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_SND_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n        }\n        if (socket_mtu) {\n            if (socket_mtu < DTLS_get_link_min_mtu(con)) {\n                BIO_printf(bio_err, "MTU too small. Must be at least %ld\\n",\n                           DTLS_get_link_min_mtu(con));\n                ret = -1;\n                BIO_free(sbio);\n                goto err;\n            }\n            SSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n            if (!DTLS_set_link_mtu(con, socket_mtu)) {\n                BIO_printf(bio_err, "Failed to set MTU\\n");\n                ret = -1;\n                BIO_free(sbio);\n                goto err;\n            }\n        } else\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n# ifndef OPENSSL_NO_SCTP\n        if (prot != IPPROTO_SCTP)\n# endif\n            SSL_set_options(con, SSL_OP_COOKIE_EXCHANGE);\n    } else\n#endif\n        sbio = BIO_new_socket(s, BIO_NOCLOSE);\n    if (sbio == NULL) {\n        BIO_printf(bio_err, "Unable to create BIO\\n");\n        ERR_print_errors(bio_err);\n        goto err;\n    }\n    if (s_nbio_test) {\n        BIO *test;\n        test = BIO_new(BIO_f_nbio_test());\n        sbio = BIO_push(test, sbio);\n    }\n    SSL_set_bio(con, sbio, sbio);\n    SSL_set_accept_state(con);\n    if (s_debug) {\n        BIO_set_callback(SSL_get_rbio(con), bio_dump_callback);\n        BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out);\n    }\n    if (s_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n        if (s_msg == 2)\n            SSL_set_msg_callback(con, SSL_trace);\n        else\n#endif\n            SSL_set_msg_callback(con, msg_cb);\n        SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);\n    }\n    if (s_tlsextdebug) {\n        SSL_set_tlsext_debug_callback(con, tlsext_cb);\n        SSL_set_tlsext_debug_arg(con, bio_s_out);\n    }\n    if (early_data) {\n        int write_header = 1, edret = SSL_READ_EARLY_DATA_ERROR;\n        size_t readbytes;\n        while (edret != SSL_READ_EARLY_DATA_FINISH) {\n            for (;;) {\n                edret = SSL_read_early_data(con, buf, bufsize, &readbytes);\n                if (edret != SSL_READ_EARLY_DATA_ERROR)\n                    break;\n                switch (SSL_get_error(con, 0)) {\n                case SSL_ERROR_WANT_WRITE:\n                case SSL_ERROR_WANT_ASYNC:\n                case SSL_ERROR_WANT_READ:\n                    continue;\n                default:\n                    BIO_printf(bio_err, "Error reading early data\\n");\n                    ERR_print_errors(bio_err);\n                    goto err;\n                }\n            }\n            if (readbytes > 0) {\n                if (write_header) {\n                    BIO_printf(bio_s_out, "Early data received:\\n");\n                    write_header = 0;\n                }\n                raw_write_stdout(buf, (unsigned int)readbytes);\n                (void)BIO_flush(bio_s_out);\n            }\n        }\n        if (write_header)\n            BIO_printf(bio_s_out, "No early data received\\n");\n        else\n            BIO_printf(bio_s_out, "\\nEnd of early data\\n");\n        if (SSL_is_init_finished(con))\n            print_connection_info(con);\n    }\n    if (fileno_stdin() > s)\n        width = fileno_stdin() + 1;\n    else\n        width = s + 1;\n    for (;;) {\n        int read_from_terminal;\n        int read_from_sslcon;\n        read_from_terminal = 0;\n        read_from_sslcon = SSL_has_pending(con)\n                           || (async && SSL_waiting_for_async(con));\n        if (!read_from_sslcon) {\n            FD_ZERO(&readfds);\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS)\n            openssl_fdset(fileno_stdin(), &readfds);\n#endif\n            openssl_fdset(s, &readfds);\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n            tv.tv_sec = 1;\n            tv.tv_usec = 0;\n            i = select(width, (void *)&readfds, NULL, NULL, &tv);\n            if (has_stdin_waiting())\n                read_from_terminal = 1;\n            if ((i < 0) || (!i && !read_from_terminal))\n                continue;\n#else\n            if ((SSL_version(con) == DTLS1_VERSION) &&\n                DTLSv1_get_timeout(con, &timeout))\n                timeoutp = &timeout;\n            else\n                timeoutp = NULL;\n            i = select(width, (void *)&readfds, NULL, NULL, timeoutp);\n            if ((SSL_version(con) == DTLS1_VERSION)\n                && DTLSv1_handle_timeout(con) > 0) {\n                BIO_printf(bio_err, "TIMEOUT occurred\\n");\n            }\n            if (i <= 0)\n                continue;\n            if (FD_ISSET(fileno_stdin(), &readfds))\n                read_from_terminal = 1;\n#endif\n            if (FD_ISSET(s, &readfds))\n                read_from_sslcon = 1;\n        }\n        if (read_from_terminal) {\n            if (s_crlf) {\n                int j, lf_num;\n                i = raw_read_stdin(buf, bufsize / 2);\n                lf_num = 0;\n                for (j = 0; j < i; j++)\n                    if (buf[j] == \'\\n\')\n                        lf_num++;\n                for (j = i - 1; j >= 0; j--) {\n                    buf[j + lf_num] = buf[j];\n                    if (buf[j] == \'\\n\') {\n                        lf_num--;\n                        i++;\n                        buf[j + lf_num] = \'\\r\';\n                    }\n                }\n                assert(lf_num == 0);\n            } else {\n                i = raw_read_stdin(buf, bufsize);\n            }\n            if (!s_quiet && !s_brief) {\n                if ((i <= 0) || (buf[0] == \'Q\')) {\n                    BIO_printf(bio_s_out, "DONE\\n");\n                    (void)BIO_flush(bio_s_out);\n                    BIO_closesocket(s);\n                    close_accept_socket();\n                    ret = -11;\n                    goto err;\n                }\n                if ((i <= 0) || (buf[0] == \'q\')) {\n                    BIO_printf(bio_s_out, "DONE\\n");\n                    (void)BIO_flush(bio_s_out);\n                    if (SSL_version(con) != DTLS1_VERSION)\n                        BIO_closesocket(s);\n                    goto err;\n                }\n#ifndef OPENSSL_NO_HEARTBEATS\n                if ((buf[0] == \'B\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n                    BIO_printf(bio_err, "HEARTBEATING\\n");\n                    SSL_heartbeat(con);\n                    i = 0;\n                    continue;\n                }\n#endif\n                if ((buf[0] == \'r\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n                    SSL_renegotiate(con);\n                    i = SSL_do_handshake(con);\n                    printf("SSL_do_handshake -> %d\\n", i);\n                    i = 0;\n                    continue;\n                }\n                if ((buf[0] == \'R\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n                    SSL_set_verify(con,\n                                   SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,\n                                   NULL);\n                    SSL_renegotiate(con);\n                    i = SSL_do_handshake(con);\n                    printf("SSL_do_handshake -> %d\\n", i);\n                    i = 0;\n                    continue;\n                }\n                if ((buf[0] == \'K\' || buf[0] == \'k\')\n                        && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n                    SSL_key_update(con, buf[0] == \'K\' ?\n                                        SSL_KEY_UPDATE_REQUESTED\n                                        : SSL_KEY_UPDATE_NOT_REQUESTED);\n                    i = SSL_do_handshake(con);\n                    printf("SSL_do_handshake -> %d\\n", i);\n                    i = 0;\n                    continue;\n                }\n                if (buf[0] == \'P\') {\n                    static const char *str = "Lets print some clear text\\n";\n                    BIO_write(SSL_get_wbio(con), str, strlen(str));\n                }\n                if (buf[0] == \'S\') {\n                    print_stats(bio_s_out, SSL_get_SSL_CTX(con));\n                }\n            }\n#ifdef CHARSET_EBCDIC\n            ebcdic2ascii(buf, buf, i);\n#endif\n            l = k = 0;\n            for (;;) {\n#ifdef RENEG\n                static count = 0;\n                if (++count == 100) {\n                    count = 0;\n                    SSL_renegotiate(con);\n                }\n#endif\n                k = SSL_write(con, &(buf[l]), (unsigned int)i);\n#ifndef OPENSSL_NO_SRP\n                while (SSL_get_error(con, k) == SSL_ERROR_WANT_X509_LOOKUP) {\n                    BIO_printf(bio_s_out, "LOOKUP renego during write\\n");\n                    SRP_user_pwd_free(srp_callback_parm.user);\n                    srp_callback_parm.user =\n                        SRP_VBASE_get1_by_user(srp_callback_parm.vb,\n                                               srp_callback_parm.login);\n                    if (srp_callback_parm.user)\n                        BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                                   srp_callback_parm.user->info);\n                    else\n                        BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n                    k = SSL_write(con, &(buf[l]), (unsigned int)i);\n                }\n#endif\n                switch (SSL_get_error(con, k)) {\n                case SSL_ERROR_NONE:\n                    break;\n                case SSL_ERROR_WANT_ASYNC:\n                    BIO_printf(bio_s_out, "Write BLOCK (Async)\\n");\n                    (void)BIO_flush(bio_s_out);\n                    wait_for_async(con);\n                    break;\n                case SSL_ERROR_WANT_WRITE:\n                case SSL_ERROR_WANT_READ:\n                case SSL_ERROR_WANT_X509_LOOKUP:\n                    BIO_printf(bio_s_out, "Write BLOCK\\n");\n                    (void)BIO_flush(bio_s_out);\n                    break;\n                case SSL_ERROR_WANT_ASYNC_JOB:\n                case SSL_ERROR_SYSCALL:\n                case SSL_ERROR_SSL:\n                    BIO_printf(bio_s_out, "ERROR\\n");\n                    (void)BIO_flush(bio_s_out);\n                    ERR_print_errors(bio_err);\n                    ret = 1;\n                    goto err;\n                case SSL_ERROR_ZERO_RETURN:\n                    BIO_printf(bio_s_out, "DONE\\n");\n                    (void)BIO_flush(bio_s_out);\n                    ret = 1;\n                    goto err;\n                }\n                if (k > 0) {\n                    l += k;\n                    i -= k;\n                }\n                if (i <= 0)\n                    break;\n            }\n        }\n        if (read_from_sslcon) {\n            if ((!async || !SSL_waiting_for_async(con))\n                    && !SSL_is_init_finished(con)) {\n                i = init_ssl_connection(con);\n                if (i < 0) {\n                    ret = 0;\n                    goto err;\n                } else if (i == 0) {\n                    ret = 1;\n                    goto err;\n                }\n            } else {\n again:\n                i = SSL_read(con, (char *)buf, bufsize);\n#ifndef OPENSSL_NO_SRP\n                while (SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) {\n                    BIO_printf(bio_s_out, "LOOKUP renego during read\\n");\n                    SRP_user_pwd_free(srp_callback_parm.user);\n                    srp_callback_parm.user =\n                        SRP_VBASE_get1_by_user(srp_callback_parm.vb,\n                                               srp_callback_parm.login);\n                    if (srp_callback_parm.user)\n                        BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                                   srp_callback_parm.user->info);\n                    else\n                        BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n                    i = SSL_read(con, (char *)buf, bufsize);\n                }\n#endif\n                switch (SSL_get_error(con, i)) {\n                case SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n                    ascii2ebcdic(buf, buf, i);\n#endif\n                    raw_write_stdout(buf, (unsigned int)i);\n                    (void)BIO_flush(bio_s_out);\n                    if (SSL_has_pending(con))\n                        goto again;\n                    break;\n                case SSL_ERROR_WANT_ASYNC:\n                    BIO_printf(bio_s_out, "Read BLOCK (Async)\\n");\n                    (void)BIO_flush(bio_s_out);\n                    wait_for_async(con);\n                    break;\n                case SSL_ERROR_WANT_WRITE:\n                case SSL_ERROR_WANT_READ:\n                    BIO_printf(bio_s_out, "Read BLOCK\\n");\n                    (void)BIO_flush(bio_s_out);\n                    break;\n                case SSL_ERROR_WANT_ASYNC_JOB:\n                case SSL_ERROR_SYSCALL:\n                case SSL_ERROR_SSL:\n                    BIO_printf(bio_s_out, "ERROR\\n");\n                    (void)BIO_flush(bio_s_out);\n                    ERR_print_errors(bio_err);\n                    ret = 1;\n                    goto err;\n                case SSL_ERROR_ZERO_RETURN:\n                    BIO_printf(bio_s_out, "DONE\\n");\n                    (void)BIO_flush(bio_s_out);\n                    ret = 1;\n                    goto err;\n                }\n            }\n        }\n    }\n err:\n    if (con != NULL) {\n        BIO_printf(bio_s_out, "shutting down SSL\\n");\n        SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n        SSL_free(con);\n    }\n    BIO_printf(bio_s_out, "CONNECTION CLOSED\\n");\n    OPENSSL_clear_free(buf, bufsize);\n    if (ret >= 0)\n        BIO_printf(bio_s_out, "ACCEPT\\n");\n    (void)BIO_flush(bio_s_out);\n    return ret;\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        goto err;\n    if (RAND_get_rand_method() == RAND_OpenSSL()) {\n        s->drbg =\n            RAND_DRBG_new(RAND_DRBG_NID, RAND_DRBG_FLAG_CTR_USE_DF,\n                          RAND_DRBG_get0_global());\n        if (s->drbg == NULL\n            || RAND_DRBG_instantiate(s->drbg,\n                                     (const unsigned char *) SSL_version_str,\n                                     sizeof(SSL_version_str) - 1) == 0) {\n            CRYPTO_THREAD_lock_free(s->lock);\n            goto err;\n        }\n    }\n    RECORD_LAYER_init(&s->rlayer, s);\n    s->options = ctx->options;\n    s->dane.flags = ctx->dane.flags;\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->max_early_data = ctx->max_early_data;\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->record_padding_cb = ctx->record_padding_cb;\n    s->record_padding_arg = ctx->record_padding_arg;\n    s->block_padding = ctx->block_padding;\n    s->sid_ctx_length = ctx->sid_ctx_length;\n    if (!ossl_assert(s->sid_ctx_length <= sizeof s->sid_ctx))\n        goto err;\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->ext.debug_cb = 0;\n    s->ext.debug_arg = NULL;\n    s->ext.ticket_expected = 0;\n    s->ext.status_type = ctx->ext.status_type;\n    s->ext.status_expected = 0;\n    s->ext.ocsp.ids = NULL;\n    s->ext.ocsp.exts = NULL;\n    s->ext.ocsp.resp = NULL;\n    s->ext.ocsp.resp_len = 0;\n    SSL_CTX_up_ref(ctx);\n    s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n    if (ctx->ext.ecpointformats) {\n        s->ext.ecpointformats =\n            OPENSSL_memdup(ctx->ext.ecpointformats,\n                           ctx->ext.ecpointformats_len);\n        if (!s->ext.ecpointformats)\n            goto err;\n        s->ext.ecpointformats_len =\n            ctx->ext.ecpointformats_len;\n    }\n    if (ctx->ext.supportedgroups) {\n        s->ext.supportedgroups =\n            OPENSSL_memdup(ctx->ext.supportedgroups,\n                           ctx->ext.supportedgroups_len\n                                * sizeof(*ctx->ext.supportedgroups));\n        if (!s->ext.supportedgroups)\n            goto err;\n        s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n    }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    s->ext.npn = NULL;\n#endif\n    if (s->ctx->ext.alpn) {\n        s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n        if (s->ext.alpn == NULL)\n            goto err;\n        memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n        s->ext.alpn_len = s->ctx->ext.alpn_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    s->key_update = SSL_KEY_UPDATE_NONE;\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->psk_find_session_cb = ctx->psk_find_session_cb;\n    s->psk_use_session_cb = ctx->psk_use_session_cb;\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_DOWN_REF(&s->references, &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    ssl_free_wbio_buffer(s);\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    SSL_SESSION_free(s->psksession);\n    OPENSSL_free(s->psksession_id);\n    clear_ciphers(s);\n    ssl_cert_free(s->cert);\n    OPENSSL_free(s->ext.hostname);\n    SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(s->ext.ecpointformats);\n    OPENSSL_free(s->ext.supportedgroups);\n#endif\n    sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n    sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n    SCT_LIST_free(s->scts);\n    OPENSSL_free(s->ext.scts);\n#endif\n    OPENSSL_free(s->ext.ocsp.resp);\n    OPENSSL_free(s->ext.alpn);\n    OPENSSL_free(s->ext.tls13_cookie);\n    OPENSSL_free(s->clienthello);\n    sk_X509_NAME_pop_free(s->ca_names, 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->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n    RAND_DRBG_free(s->drbg);\n    CRYPTO_THREAD_lock_free(s->lock);\n    OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n    int i;\n    if (a == NULL)\n        return;\n    CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n    REF_PRINT_COUNT("SSL_CTX", a);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(a->param);\n    dane_ctx_final(&a->dane);\n    if (a->sessions != NULL)\n        SSL_CTX_flush_sessions(a, 0);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n    lh_SSL_SESSION_free(a->sessions);\n    X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n    CTLOG_STORE_free(a->ctlog_store);\n#endif\n    sk_SSL_CIPHER_free(a->cipher_list);\n    sk_SSL_CIPHER_free(a->cipher_list_by_id);\n    ssl_cert_free(a->cert);\n    sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n    sk_X509_pop_free(a->extra_certs, X509_free);\n    a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n    SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(a->ext.ecpointformats);\n    OPENSSL_free(a->ext.supportedgroups);\n#endif\n    OPENSSL_free(a->ext.alpn);\n    CRYPTO_THREAD_lock_free(a->lock);\n    OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n    unsigned long i;\n    TIMEOUT_PARAM tp;\n    tp.ctx = s;\n    tp.cache = s->sessions;\n    if (tp.cache == NULL)\n        return;\n    tp.time = t;\n    CRYPTO_THREAD_write_lock(s->lock);\n    i = lh_SSL_SESSION_get_down_load(s->sessions);\n    lh_SSL_SESSION_set_down_load(s->sessions, 0);\n    lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n    lh_SSL_SESSION_set_down_load(s->sessions, i);\n    CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n    doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n                          OPENSSL_LH_DOALL_FUNC func,\n                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n    int i;\n    OPENSSL_LH_NODE *a, *n;\n    if (lh == NULL)\n        return;\n    for (i = lh->num_nodes - 1; i >= 0; i--) {\n        a = lh->b[i];\n        while (a != NULL) {\n            n = a->next;\n            if (use_arg)\n                func_arg(a->data, arg);\n            else\n                func(a->data);\n            a = n;\n        }\n    }\n}']