Fixing some memory leaks on Agent reconnect

Hi guys! Thanks for the great package.
But keeping open several (4.. 6) connections on a machine with ~ 500 Mb RAM makes a process (runed without forever) to fall after 5 .. 10 hrs. 
Looks like this fix solved the problem. I've also tried to comment the function in your style.

Well, here is pull request, and thank you again for your package.
I think your editor is set up for 4 spaces as tabs, however this library uses 2 spaces as tabs. Could you please revise the style.