I have a tcp connection with a timer. When the connection receives EOF, I 
would close the connection and release all the resources.
Code snippet:

void LogicServer::OnMsgRecv(uv_stream_t *client, ssize_t nread, const 
uv_buf_t *buf){
auto connection_pos = open_sessions.find(client);
if (connection_pos != open_sessions.end())
{
bool reset_timer = false;
if (nread == UV_EOF)
{
fprintf(stdout, "Client Disconnected\r\n");
RemoveClient(client);
}
free(buf->base);
}
}

void LogicServer::RemoveClient(uv_stream_t* client)
{
auto connection_pos = open_sessions.find(client);
if (connection_pos != open_sessions.end())
{
//stop timer
//uv_timer_stop(connection_pos->second->activity_timer);
//uv_close((uv_handle_t*)connection_pos->second->activity_timer, NULL);

uv_read_stop(client);
uv_close((uv_handle_t*)client,
[](uv_handle_t* handle)
{
LogicServer::GetInstance()->OnConnectionClose(handle);
});
}
}

The question is : Why does the program crash after I call the uv_close to 
close the uv_timer_t?And it will leak memory if I don't call uv_close.
What's the problem with that ?How can I close the connection with the timer 
safely?  Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to