zaphoyd/websocketpp — Issue #48: A few memory leaks
Author: megabyte1024
Created: 2012-01-13 08:50:20+00:00
State: open

There are the following memory leaks:

1. class client contains a shared pointer to a client session object (m_client_session), which is instanced in the client::init method. Also the client_session class contains a shared pointer to the parent session m_client. Instancing the client class object as its shared pointer reference counter equals to 1, after calling its init method the reference counter equals to 2, due to the reference in the session object. By deleting the client object reference becomes to 1 and the client object is never deleted.
To resolve this cyclic dependency is necessary to use the boost::weak_ptr class instead of boost::shared_ptr for the client_session::m_client member.

2. A similar cyclic dependency between the server and server_session classes. The server_session::m_server member type changing to boost::weak_ptr is required to fix it.

3. If a server is stopped by calling of the stop method of the parent boost::asio::io_service instance and the server has connected clients, when active connections which are stored in connection_handler inherited class (the example chat_server_handler class) are not deleted. A fast but not universal solution to fix this issue is to mandatory clear the connections list (chat_server_handler::m_connections) after call of io_service.run.