-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fixed memory leaks when stopping io_service::stop (issue #490). #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…. This fix passes callbacks bound to weak_ptr's instead of shared_ptr's.
Xavier, Firstly, thanks for taking a crack at this one. I've done a fair bit of testing with the solutions I've been toying with as well as your solution, and have determined that there isn't a safe way to manage the connection reference counts without either getting rid of the cached handlers or keeping a global list of all connections. The performance improvement for cached handlers is not as great as the performance improvement for not having a global connection list so I am removing the cached handlers. This should fix issue #490 and make it "safe" at least from a resource leak perspective to call endpoint/io_service::stop at any time. I've tested a bit with valgrind and the toy programs that leaked before don't seem to anymore. If you could confirm, that would be great. |
Hi Peter, Thank you for releasing a new version. I tried running the unit tests
I attach the logs for your reference. Xavier On 21.02.2016 15:42, Peter Thorson wrote:
Links:[1] #490 exec ${PAGER:-/usr/bin/less} "$0" || exit 1Running 17 test cases... *** No errors detected ==93388==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 17880 byte(s) in 1 object(s) allocated from: Indirect leak of 17840 byte(s) in 1 object(s) allocated from: Indirect leak of 17840 byte(s) in 1 object(s) allocated from: Indirect leak of 17840 byte(s) in 1 object(s) allocated from: Indirect leak of 17840 byte(s) in 1 object(s) allocated from: Indirect leak of 1430 byte(s) in 20 object(s) allocated from: Indirect leak of 576 byte(s) in 2 object(s) allocated from: |
This fix passes callbacks bound to weak_ptr's instead of shared_ptr's. This binds a helper function that tries to lock the weak_ptr before executing the callback. This is implemented using variadic templates, which are C++11 only. If C++03 compatibility is required, this could be also be implemented using variadic macros.