From 22cb49b9105657cafb98624be37f05b169f73dd6 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Wed, 1 Aug 2018 15:24:20 +0200 Subject: server: Avoid FD leak in error cases Spotted by coverity. --- p11-kit/server.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'p11-kit') diff --git a/p11-kit/server.c b/p11-kit/server.c index 87d6ad4..a737c2a 100644 --- a/p11-kit/server.c +++ b/p11-kit/server.c @@ -277,12 +277,14 @@ create_socket (const char *address, umask (066); rc = bind (sd, (struct sockaddr *)&sa, SUN_LEN (&sa)); if (rc == -1) { + close (sd); p11_message_err (errno, "could not bind socket %s", socket_file); return -1; } rc = listen (sd, 1024); if (rc == -1) { + close (sd); p11_message_err (errno, "could not listen to socket %s", socket_file); return 1; } @@ -290,6 +292,7 @@ create_socket (const char *address, if (uid != -1 && gid != -1) { rc = chown (socket_file, uid, gid); if (rc == -1) { + close (sd); p11_message_err (errno, "could not chown socket %s", socket_file); return -1; } -- cgit v1.1