Prevent badly closing socket

- Initialize socket to -1
- Only close if >= 0

Fix #6