Properly close socket in case of socket creation error