void *lh_delete(_LHASH *lh, const void *data)
	{
	unsigned long hash;
	LHASH_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);
	}
['static HEARTBEAT_TEST_FIXTURE set_up(const char* const test_case_name,\n\tconst SSL_METHOD* meth)\n\t{\n\tHEARTBEAT_TEST_FIXTURE fixture;\n\tint setup_ok = 1;\n\tmemset(&fixture, 0, sizeof(fixture));\n\tfixture.test_case_name = test_case_name;\n\tfixture.ctx = SSL_CTX_new(meth);\n\tif (!fixture.ctx)\n\t\t{\n\t\tfprintf(stderr, "Failed to allocate SSL_CTX for test: %s\\n",\n\t\t\ttest_case_name);\n\t\tsetup_ok = 0;\n\t\tgoto fail;\n\t\t}\n\tfixture.s = SSL_new(fixture.ctx);\n\tif (!fixture.s)\n\t\t{\n\t\tfprintf(stderr, "Failed to allocate SSL for test: %s\\n", test_case_name);\n\t\tsetup_ok = 0;\n\t\tgoto fail;\n\t\t}\n\tif (!ssl_init_wbio_buffer(fixture.s, 1))\n\t\t{\n\t\tfprintf(stderr, "Failed to set up wbio buffer for test: %s\\n",\n\t\t\ttest_case_name);\n\t\tsetup_ok = 0;\n\t\tgoto fail;\n\t\t}\n\tif (!ssl3_setup_buffers(fixture.s))\n\t\t{\n\t\tfprintf(stderr, "Failed to setup buffers for test: %s\\n",\n\t\t\ttest_case_name);\n\t\tsetup_ok = 0;\n\t\tgoto fail;\n\t\t}\n\tfail:\n\tif (!setup_ok)\n\t\t{\n\t\tERR_print_errors_fp(stderr);\n\t\texit(EXIT_FAILURE);\n\t\t}\n\treturn fixture;\n\t}', 'SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)\n\t{\n\tSSL_CTX *ret=NULL;\n\tif (meth == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);\n\t\treturn(NULL);\n\t\t}\n#ifdef OPENSSL_FIPS\n\tif (FIPS_mode() && (meth->version < TLS1_VERSION))\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE);\n\t\treturn NULL;\n\t\t}\n#endif\n\tif (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n\t\tgoto err;\n\t\t}\n\tret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));\n\tif (ret == NULL)\n\t\tgoto err;\n\tmemset(ret,0,sizeof(SSL_CTX));\n\tret->method=meth;\n\tret->cert_store=NULL;\n\tret->session_cache_mode=SSL_SESS_CACHE_SERVER;\n\tret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n\tret->session_cache_head=NULL;\n\tret->session_cache_tail=NULL;\n\tret->session_timeout=meth->get_timeout();\n\tret->new_session_cb=0;\n\tret->remove_session_cb=0;\n\tret->get_session_cb=0;\n\tret->generate_session_id=0;\n\tmemset((char *)&ret->stats,0,sizeof(ret->stats));\n\tret->references=1;\n\tret->quiet_shutdown=0;\n\tret->info_callback=NULL;\n\tret->app_verify_callback=0;\n\tret->app_verify_arg=NULL;\n\tret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT;\n\tret->read_ahead=0;\n\tret->msg_callback=0;\n\tret->msg_callback_arg=NULL;\n\tret->verify_mode=SSL_VERIFY_NONE;\n#if 0\n\tret->verify_depth=-1;\n#endif\n\tret->sid_ctx_length=0;\n\tret->default_verify_callback=NULL;\n\tif ((ret->cert=ssl_cert_new()) == NULL)\n\t\tgoto err;\n\tret->default_passwd_callback=0;\n\tret->default_passwd_callback_userdata=NULL;\n\tret->client_cert_cb=0;\n\tret->app_gen_cookie_cb=0;\n\tret->app_verify_cookie_cb=0;\n\tret->sessions=lh_SSL_SESSION_new();\n\tif (ret->sessions == NULL) goto err;\n\tret->cert_store=X509_STORE_new();\n\tif (ret->cert_store == NULL) goto err;\n\tssl_create_cipher_list(ret->method,\n\t\t&ret->cipher_list,&ret->cipher_list_by_id,\n\t\tmeth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST, ret->cert);\n\tif (ret->cipher_list == NULL\n\t    || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);\n\t\tgoto err2;\n\t\t}\n\tret->param = X509_VERIFY_PARAM_new();\n\tif (!ret->param)\n\t\tgoto err;\n\tif ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)\n\t\tgoto err;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);\n\tret->extra_certs=NULL;\n\tif (!(meth->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS))\n\t\tret->comp_methods=SSL_COMP_get_compression_methods();\n\tret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n#ifndef OPENSSL_NO_TLSEXT\n\tret->tlsext_servername_callback = 0;\n\tret->tlsext_servername_arg = NULL;\n\tif ((RAND_pseudo_bytes(ret->tlsext_tick_key_name, 16) <= 0)\n\t\t|| (RAND_bytes(ret->tlsext_tick_hmac_key, 16) <= 0)\n\t\t|| (RAND_bytes(ret->tlsext_tick_aes_key, 16) <= 0))\n\t\tret->options |= SSL_OP_NO_TICKET;\n\tret->tlsext_status_cb = 0;\n\tret->tlsext_status_arg = NULL;\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\tret->next_protos_advertised_cb = 0;\n\tret->next_proto_select_cb = 0;\n# endif\n#endif\n#ifndef OPENSSL_NO_PSK\n\tret->psk_identity_hint=NULL;\n\tret->psk_client_callback=NULL;\n\tret->psk_server_callback=NULL;\n#endif\n#ifndef OPENSSL_NO_SRP\n\tSSL_CTX_SRP_CTX_init(ret);\n#endif\n\tret->custom_cli_ext_records = NULL;\n\tret->custom_cli_ext_records_count = 0;\n\tret->custom_srv_ext_records = NULL;\n\tret->custom_srv_ext_records_count = 0;\n\tret->cli_supp_data_records = NULL;\n\tret->cli_supp_data_records_count = 0;\n\tret->srv_supp_data_records = NULL;\n\tret->srv_supp_data_records_count = 0;\n#ifndef OPENSSL_NO_BUF_FREELISTS\n\tret->freelist_max_len = SSL_MAX_BUF_FREELIST_LEN_DEFAULT;\n\tret->rbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST));\n\tif (!ret->rbuf_freelist)\n\t\tgoto err;\n\tret->rbuf_freelist->chunklen = 0;\n\tret->rbuf_freelist->len = 0;\n\tret->rbuf_freelist->head = NULL;\n\tret->wbuf_freelist = OPENSSL_malloc(sizeof(SSL3_BUF_FREELIST));\n\tif (!ret->wbuf_freelist)\n\t\t{\n\t\tOPENSSL_free(ret->rbuf_freelist);\n\t\tgoto err;\n\t\t}\n\tret->wbuf_freelist->chunklen = 0;\n\tret->wbuf_freelist->len = 0;\n\tret->wbuf_freelist->head = NULL;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\tret->client_cert_engine = NULL;\n#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO\n#define eng_strx(x)\t#x\n#define eng_str(x)\teng_strx(x)\n\t{\n\tENGINE *eng;\n\teng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n\tif (!eng)\n\t\t{\n\t\tERR_clear_error();\n\t\tENGINE_load_builtin_engines();\n\t\teng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n\t\t}\n\tif (!eng || !SSL_CTX_set_client_cert_engine(ret, eng))\n\t\tERR_clear_error();\n\t}\n#endif\n#endif\n\tret->options |= SSL_OP_LEGACY_SERVER_CONNECT;\n\treturn(ret);\nerr:\n\tSSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);\nerr2:\n\tif (ret != NULL) SSL_CTX_free(ret);\n\treturn(NULL);\n\t}', '_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n\t{\n\t_LHASH *ret;\n\tint i;\n\tif ((ret=OPENSSL_malloc(sizeof(_LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);\n\tret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tOPENSSL_free(ret);\nerr0:\n\treturn(NULL);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->not_resumable_session_cb=ctx->not_resumable_session_cb;\n#if 0\n\ts->verify_depth=ctx->verify_depth;\n#endif\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tOPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->param = X509_VERIFY_PARAM_new();\n\tif (!s->param)\n\t\tgoto err;\n\tX509_VERIFY_PARAM_inherit(s->param, ctx->param);\n#if 0\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n#endif\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->max_send_fragment = ctx->max_send_fragment;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n#ifndef OPENSSL_NO_TLSEXT\n\ts->tlsext_debug_cb = 0;\n\ts->tlsext_debug_arg = NULL;\n\ts->tlsext_ticket_expected = 0;\n\ts->tlsext_status_type = -1;\n\ts->tlsext_status_expected = 0;\n\ts->tlsext_ocsp_ids = NULL;\n\ts->tlsext_ocsp_exts = NULL;\n\ts->tlsext_ocsp_resp = NULL;\n\ts->tlsext_ocsp_resplen = -1;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->initial_ctx=ctx;\n#ifndef OPENSSL_NO_EC\n\tif (ctx->tlsext_ecpointformatlist)\n\t\t{\n\t\ts->tlsext_ecpointformatlist =\n\t\t\tBUF_memdup(ctx->tlsext_ecpointformatlist,\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length);\n\t\tif (!s->tlsext_ecpointformatlist)\n\t\t\tgoto err;\n\t\ts->tlsext_ecpointformatlist_length =\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length;\n\t\t}\n\tif (ctx->tlsext_ellipticcurvelist)\n\t\t{\n\t\ts->tlsext_ellipticcurvelist =\n\t\t\tBUF_memdup(ctx->tlsext_ellipticcurvelist,\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length);\n\t\tif (!s->tlsext_ellipticcurvelist)\n\t\t\tgoto err;\n\t\ts->tlsext_ellipticcurvelist_length =\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length;\n\t\t}\n#endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\ts->next_proto_negotiated = NULL;\n# endif\n\tif (s->ctx->alpn_client_proto_list)\n\t\t{\n\t\ts->alpn_client_proto_list =\n\t\t\tOPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n\t\tif (s->alpn_client_proto_list == NULL)\n\t\t\tgoto err;\n\t\tmemcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n\t\t       s->ctx->alpn_client_proto_list_len);\n\t\ts->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n\t\t}\n#endif\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n\ts->psk_client_callback=ctx->psk_client_callback;\n\ts->psk_server_callback=ctx->psk_server_callback;\n#endif\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->renegotiate) return(1);\n#else\n\tif (s->renegotiate)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tssl_clear_hash_ctx(&s->read_hash);\n\tssl_clear_hash_ctx(&s->write_hash);\n\ts->first_packet=0;\n#if 1\n\tif (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=lh_SSL_SESSION_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(_LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']