The old code leaked the open socket fd in case of errors.
{
int fd, ret;
- fd = socket(PF_UNIX, SOCK_STREAM, 0);
- if (fd < 0)
- return -E_SOCKET;
-// unlink(name);
ret = init_unix_addr(unix_addr, name);
if (ret < 0)
return ret;
+ fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0)
+ return -E_SOCKET;
+ ret = -E_BIND;
if (bind(fd, (struct sockaddr *) unix_addr, UNIX_PATH_MAX) < 0)
- return -E_BIND;
+ goto err;
+ ret = -E_CHMOD;
if (chmod(name, mode) < 0)
- return -E_CHMOD;
+ goto err;
return fd;
+err:
+ close(fd);
+ return ret;
}
#ifndef HAVE_UCRED