只能在uv_close之后的uv_cb中对handle内存进行释放。
因为uv_close本身只是将handle代释放队列,倘若释放时遇到某些异步处理(如:uv_write)需要失败回调通知,将会继续调用对应的回调,此时再访问handle和可能因内存访问coredump。
void TcpHandler::bind(uv_loop_t& loop){
tcp = Holder<uv_tcp_t, TcpHandler>::create(std::static_pointer_cast<TcpHandler>(shared_from_this()));
uv_tcp_init(&loop, tcp.get());
tcp->data = this;
}
void TcpHandler::unbind() {
uv_close((uv_handle_t*)(tcp.get()), [](auto* handle){
auto tcpHandler = getHandler((uv_tcp_t*)handle) ;
tcpHandler->tcp = nullptr;
});
}