zaphoyd/websocketpp — pull request #334 by aydany (2014-03-04 03:01:02+00:00)
Title: Avoid leak when stopping server

If accept fails, e.g., because the server is no longer listening the
connection object is not terminated and it results in a memory leak:
connection -> handler -> connection.

Note: terminating connections that are not "accepted" results in asio error 10009 (invalid socket), since the OS socket is not created until accept succeeds. While this error appears to be harmless con->terminate() probably needs to be reworked to avoid generating a spurious log warning.

In addition, during stop, the endpoint goes through the accept loop one time too many: stop_listening() results in the current accept to fail with operation_cancelled, but then handle_accept calls accept_async unconditionally. In this case the call to accept_async is not necessary.

Thanks,
--aydan