Skip to content

Commit 131e771

Browse files
committed
Fix two coverity issues
* resource leak * make sure argument to connect is not negative
1 parent 68c516c commit 131e771

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/gateway.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,21 @@ void get_clients_from_parent(void) {
123123

124124
/* Connect to socket */
125125
sock = socket(AF_UNIX, SOCK_STREAM, 0);
126+
/* XXX An attempt to quieten coverity warning about the subsequent connect call:
127+
* Coverity says: "sock is apssed to parameter that cannot be negative"
128+
* Although connect expects a signed int, coverity probably tells us that it shouldn't
129+
* be negative */
130+
if (sock < 0) {
131+
debug(LOG_ERR, "Could not open socket (%s) - client list not downloaded", strerror(errno));
132+
return;
133+
}
126134
memset(&sa_un, 0, sizeof(sa_un));
127135
sa_un.sun_family = AF_UNIX;
128136
strncpy(sa_un.sun_path, config->internal_sock, (sizeof(sa_un.sun_path) - 1));
129137

130138
if (connect(sock, (struct sockaddr *)&sa_un, strlen(sa_un.sun_path) + sizeof(sa_un.sun_family))) {
131139
debug(LOG_ERR, "Failed to connect to parent (%s) - client list not downloaded", strerror(errno));
140+
close(sock);
132141
return;
133142
}
134143

0 commit comments

Comments
 (0)