fix resource warnings

by closing sockets properly