@@ -76,15 +76,17 @@ static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
int unix_stream_connect(const char *path)
{
- int fd, saved_errno;
+ int fd = -1;
+ int saved_errno;
struct sockaddr_un sa;
struct unix_sockaddr_context ctx = UNIX_SOCKADDR_CONTEXT_INIT;
if (unix_sockaddr_init(&sa, path, &ctx) < 0)
return -1;
+
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
- die_errno("unable to create socket");
+ goto fail;
if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
goto fail;
@@ -94,7 +96,8 @@ int unix_stream_connect(const char *path)
fail:
saved_errno = errno;
unix_sockaddr_cleanup(&ctx);
- close(fd);
+ if (fd != -1)
+ close(fd);
errno = saved_errno;
return -1;
}