Don't compare socket results to -1 but to INVALID_SOCKET
Fix memory leak
Move variable declarations to point of first use.
Don't leak sockets on error
Comment formatting.