Wait - you suppose it's a memory leak? You're not sure? Why do you think it's a memory leak?

You aren't going to find solutions to your problems unless you describe them correctly. Use a tool like 'top' to monitor your application's memory usage over time, and see if it increases indefinitely. Or if there's some runaway CPU process bogging down the system. Or try netstat if you're connecting to a remote server, to see if there's some aberrant network activity that might be causing the slowdown.

Or, if you're really fixated on believing it's a memory issue, why not simply try destroying the connection you started off suspecting, and see if that makes the problem go away?

Or you can continue to pore over the valgrind output, looking for bytes marked as definitely lost; as you can see, it provides references back to the line in your source code where the problem originated.