Close socket on error (and shut up analyzer warning)