add: err: if (ret < 0) { int tmpret, saved_errno = errno;   tmpret = close(sock); assert(tmpret >= 0);   errno = saved_errno; } return ret;
context: int netcat_socket_new_connect(int domain, int type, const struct in_addr *addr,		unsigned short port, const struct in_addr *local_addr,		unsigned short local_port){  int sock, ret;  struct sockaddr_in rem_addr;  debug_dv("netcat_socket_new_connect(addr=%p, port=%hu, local_addr=%p, local"	   "_port=%hu)", (void *)addr, port, (void *)local_addr, local_port);  rem_addr.sin_family = AF_INET;  rem_addr.sin_port = htons(port);  memcpy(&rem_addr.sin_addr, addr, sizeof(rem_addr.sin_addr));  /* create the socket and fix the options */  sock = netcat_socket_new(domain, type);  if (sock < 0)    return sock;  /* only if needed, bind it to a local address */  if (local_addr || local_port) {    struct sockaddr_in my_addr;    my_addr.sin_family = AF_INET;    my_addr.sin_port = htons(local_port);    /* local_addr may not be specified because the user may want to only enforce       the local source port */    if (local_addr)      memcpy(&my_addr.sin_addr, local_addr, sizeof(my_addr.sin_addr));    else      memset(&my_addr.sin_addr, 0, sizeof(my_addr.sin_addr));    ret = bind(sock, (struct sockaddr *)&my_addr, sizeof(my_addr));    if (ret < 0)      return -3;  }  /* add the non-blocking flag to this socket */  ret = fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK);  if (ret < 0)    return -4;  /* now launch the real connection. Since we are in non-blocking mode, this     call will return -1 in MOST cases (on some systems, a connect() to a local     address may immediately return successfully) */  ret = connect(sock, (struct sockaddr *)&rem_addr, sizeof(rem_addr));  if ((ret < 0) && (errno != EINPROGRESS))    return -5;  return sock;}