Fix Memoryleak

remove sockets when not needed