只能在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;
    });
}

  

相关文章:

  • 2019-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-05-22
  • 2022-12-23
  • 2022-01-21
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2021-07-09
  • 2021-06-16
  • 2021-10-01
  • 2021-08-08
相关资源
相似解决方案