From 827f3678bb66244aa2de317bd81af176d54b7614 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Tue, 26 Nov 2013 22:05:26 -0600 Subject: [PATCH] Fixes a leak of connection objects when using asio transport references #310 --- changelog.md | 2 ++ websocketpp/transport/asio/connection.hpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 51886ddc0f..a51f4b69ab 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,8 @@ HEAD buffer sizes based on profiling, caching of handler binding for async reads/writes, non-malloc allocators for read/write handlers, disabling of a number of questionably useful range sanity checks in tight inner loops. +- Bug: Fix memory leak of connection objects due to cached handlers holding on to + reference counted pointers. #310 Thank you otaras for reporting. - Bug: Fix issue with const endpoint accessors (such as `get_user_agent`) not compiling due to non-const mutex use. #292 Thank you logofive for reporting. - Bug: Fix handler allocation crash with multithreaded io_service. diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 6b68982318..79bc1a6083 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -909,6 +909,13 @@ protected: m_alog.write(log::alevel::devel,"asio connection async_shutdown"); } + // Reset cached handlers now that we won't be reading or writing anymore + // These cached handlers store shared pointers to this connection and will leak + // the connection if not destroyed. + m_async_read_handler = 0; + m_async_write_handler = 0; + m_init_handler = 0; + timer_ptr shutdown_timer; shutdown_timer = set_timer( config::timeout_socket_shutdown,