修复多处内存泄漏。
This commit is contained in:
@@ -291,8 +291,8 @@ typedef void (http_session_end_cb)(const struct tfe_stream * stream,
|
||||
/* Tools functions for standard HTTP header field name */
|
||||
struct http_field_name * http_field_name_duplicate(const struct http_field_name * orig);
|
||||
int http_field_name_compare(const struct http_field_name * lvalue, const struct http_field_name * rvalue);
|
||||
const char * http_field_to_string(const struct http_field_name * field);
|
||||
void http_field_destory(struct http_field_name *);
|
||||
const char * http_field_name_to_string(const struct http_field_name * field);
|
||||
void http_field_name_destory(struct http_field_name *);
|
||||
|
||||
/* Tools functions for standard HTTP method */
|
||||
const char * http_std_method_to_string(enum tfe_http_std_method method);
|
||||
|
||||
@@ -117,6 +117,7 @@ const char * http_field_to_string(const struct http_field_name * field)
|
||||
|
||||
void http_field_destory(struct http_field_name * field)
|
||||
{
|
||||
if(field->field_id == TFE_HTTP_UNKNOWN_FIELD) FREE(&field->field_name);
|
||||
free(field);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ struct tfe_rpc_ctx
|
||||
{
|
||||
struct event_base * evbase;
|
||||
enum TFE_RPC_FLAG flag;
|
||||
struct evhttp_connection* connection;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -41,6 +42,9 @@ int read_header_done_cb(struct evhttp_request* response, void* arg)
|
||||
|
||||
static void tfe_rpc_promise_free_ctx(void* ctx)
|
||||
{
|
||||
struct tfe_rpc_ctx* _ctx=(struct tfe_rpc_ctx*)ctx;
|
||||
evhttp_connection_free(_ctx->connection);
|
||||
_ctx->connection=NULL;
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
return;
|
||||
@@ -190,13 +194,13 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
|
||||
if(NULL == uri)
|
||||
{
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse url failed!");
|
||||
return;
|
||||
goto error_out;
|
||||
}
|
||||
const char* host = evhttp_uri_get_host(uri);
|
||||
if(!host)
|
||||
{
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "parse host failed!");
|
||||
return;
|
||||
goto error_out;
|
||||
}
|
||||
int port = evhttp_uri_get_port(uri);
|
||||
if(port < 0)
|
||||
@@ -204,13 +208,13 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
|
||||
port = 80;
|
||||
}
|
||||
|
||||
struct evhttp_connection* connection = evhttp_connection_base_new(evbase, dnsbase, host, port);
|
||||
if (!connection)
|
||||
ctx->connection = evhttp_connection_base_new(evbase, dnsbase, host, port);
|
||||
if (!ctx->connection)
|
||||
{
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "create connection failed!");
|
||||
return;
|
||||
goto error_out;
|
||||
}
|
||||
evhttp_connection_set_closecb(connection, connection_close_cb, evbase);
|
||||
evhttp_connection_set_closecb(ctx->connection, connection_close_cb, evbase);
|
||||
struct evhttp_request* request = evhttp_request_new(get_response_cb, (void*)p);
|
||||
//evhttp_request_set_header_cb(request, read_header_done_cb);
|
||||
if(flag == CHUNK_CB)
|
||||
@@ -225,22 +229,30 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
|
||||
if(request_url == NULL)
|
||||
{
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "get request url failed");
|
||||
return;
|
||||
goto error_out;
|
||||
}
|
||||
switch(method)
|
||||
{
|
||||
case GET:
|
||||
evhttp_make_request(connection, request, EVHTTP_REQ_GET, request_url);
|
||||
evhttp_make_request(ctx->connection, request, EVHTTP_REQ_GET, request_url);
|
||||
break;
|
||||
case POST:
|
||||
evbuffer_add(request->output_buffer, data, data_len);
|
||||
evhttp_make_request(connection, request, EVHTTP_REQ_POST, request_url);
|
||||
evhttp_make_request(ctx->connection, request, EVHTTP_REQ_POST, request_url);
|
||||
break;
|
||||
default:
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "method is invalid!");
|
||||
return;
|
||||
goto error_out;
|
||||
}
|
||||
free(request_url);
|
||||
evhttp_uri_free(uri);
|
||||
return;
|
||||
|
||||
error_out:
|
||||
if(uri) evhttp_uri_free(uri);
|
||||
promise_dettach_ctx(p);
|
||||
tfe_rpc_promise_free_ctx(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
struct tfe_rpc_response_result* tfe_rpc_release(void* result)
|
||||
|
||||
@@ -300,12 +300,12 @@ static struct keyring_private* get_keyring_from_response(const char* data)
|
||||
STACK_OF(X509)* chain = NULL;
|
||||
if(data == NULL)
|
||||
{
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
cJSON* data_json = cJSON_Parse(data);
|
||||
if(data_json == NULL)
|
||||
{
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
cJSON* cert_json = NULL;
|
||||
cJSON* key_json = NULL;
|
||||
@@ -319,8 +319,7 @@ static struct keyring_private* get_keyring_from_response(const char* data)
|
||||
}
|
||||
if(cert == NULL)
|
||||
{
|
||||
err_out(cert, key, chain);
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
if (key_json && key_json->valuestring != NULL)
|
||||
{
|
||||
@@ -328,13 +327,11 @@ static struct keyring_private* get_keyring_from_response(const char* data)
|
||||
}
|
||||
if(key == NULL)
|
||||
{
|
||||
err_out(cert, key, chain);
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
if(chain_json == NULL)
|
||||
{
|
||||
err_out(cert, key, chain);
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
cJSON* chain_cert_json = NULL;
|
||||
chain = sk_X509_new_null();
|
||||
@@ -347,8 +344,7 @@ static struct keyring_private* get_keyring_from_response(const char* data)
|
||||
}
|
||||
if(chain_cert == NULL)
|
||||
{
|
||||
err_out(cert, key, chain);
|
||||
return NULL;
|
||||
goto error_out;
|
||||
}
|
||||
sk_X509_push(chain, chain_cert);
|
||||
ssl_x509_refcount_inc(chain_cert);
|
||||
@@ -360,7 +356,16 @@ static struct keyring_private* get_keyring_from_response(const char* data)
|
||||
X509_free(cert);
|
||||
EVP_PKEY_free(key);
|
||||
sk_X509_pop_free(chain, X509_free);
|
||||
cJSON_free(data_json);
|
||||
return _kyr;
|
||||
|
||||
error_out:
|
||||
if(data_json!=NULL) cJSON_free(data_json);
|
||||
if(cert) X509_free(cert);
|
||||
if(key) EVP_PKEY_free(key);
|
||||
if(chain) sk_X509_pop_free(chain, X509_free);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
static long keyring_local_cache_query_cb(void * data, const uchar * key, uint size, void * user_arg)
|
||||
@@ -600,6 +605,7 @@ char* url_escape(char* url)
|
||||
{
|
||||
_url = curl_easy_escape(curl, url, strlen(url));
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
return _url;
|
||||
}
|
||||
|
||||
|
||||
@@ -1434,7 +1434,7 @@ void ssl_connect_client_ctx_free(struct ssl_connect_client_ctx * ctx)
|
||||
{
|
||||
ssl_stream_free(ctx->downstream);
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -463,6 +463,7 @@ void http_repl_ctx_free(struct replace_ctx* rep_ctx)
|
||||
FREE(&(rep_ctx->rule[i].find));
|
||||
FREE(&(rep_ctx->rule[i].replace_with));
|
||||
}
|
||||
FREE(&(rep_ctx->rule));
|
||||
if (rep_ctx->http_body)
|
||||
{
|
||||
evbuffer_free(rep_ctx->http_body);
|
||||
@@ -939,7 +940,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
|
||||
break;
|
||||
}
|
||||
|
||||
const char * str_field_name = http_field_to_string(&field_name);
|
||||
const char * str_field_name = http_field_name_to_string(&field_name);
|
||||
scan_ret = Maat_set_scan_status(g_pangu_rt->maat, &(ctx->scan_mid), MAAT_SET_SCAN_DISTRICT,
|
||||
str_field_name, strlen(str_field_name));
|
||||
|
||||
|
||||
@@ -709,7 +709,7 @@ void hf_private_destory(struct http_half_private * hf_private)
|
||||
TAILQ_FOREACH_SAFE(header_iter, &hf_private->header_list, next, header_titer)
|
||||
{
|
||||
TAILQ_REMOVE(&hf_private->header_list, header_iter, next);
|
||||
free(header_iter->field);
|
||||
http_field_name_destory(header_iter->field);
|
||||
free(header_iter->value);
|
||||
free(header_iter);
|
||||
}
|
||||
@@ -1110,7 +1110,7 @@ void hf_private_construct(struct http_half_private * hf_private)
|
||||
for (const char * str_value = tfe_http_field_iterate(hf_public, &iterator, &field_name);
|
||||
str_value != NULL; str_value = tfe_http_field_iterate(hf_public, &iterator, &field_name))
|
||||
{
|
||||
const char * str_field = http_field_to_string(&field_name);
|
||||
const char * str_field = http_field_name_to_string(&field_name);
|
||||
evbuffer_add_printf(hf_private->evbuf_raw, "%s: %s\r\n", str_field, str_value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user