Skip to content

Commit fe00a84

Browse files
committed
Merge pull request zaphoyd#333 from aydany/master
Fix memory leak when init_asio fails
2 parents c5b5492 + 337bf2f commit fe00a84

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

websocketpp/transport/asio/connection.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,15 @@ class connection : public config::socket_type::socket_con_type {
443443
m_async_write_handler = lib::bind(&type::handle_async_write,
444444
get_shared(), lib::placeholders::_1, lib::placeholders::_2);
445445
}
446-
447-
return socket_con_type::init_asio(io_service, m_strand, m_is_server);
446+
447+
lib::error_code ec = socket_con_type::init_asio(io_service, m_strand, m_is_server);
448+
if (ec) {
449+
// reset the handlers to break the circular reference: this->handler->this
450+
m_async_read_handler = _WEBSOCKETPP_NULLPTR_TOKEN_;
451+
m_async_write_handler = _WEBSOCKETPP_NULLPTR_TOKEN_;
452+
}
453+
454+
return ec;
448455
}
449456

450457
void handle_pre_init(lib::error_code const & ec) {

0 commit comments

Comments
 (0)