修复多处内存泄漏。
This commit is contained in:
@@ -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)
|
||||
@@ -224,23 +228,31 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
|
||||
//printf("request url is %s\n", request_url);
|
||||
if(request_url == NULL)
|
||||
{
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "get request url failed");
|
||||
return;
|
||||
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "get request url failed");
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user