Fix some memory problems with sockets. Still some problems left, as one run of the tests errored out.