Skip to content

Commit ff61d85

Browse files
committed
Prevent fd leak
1 parent 19ad00a commit ff61d85

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/wdctl_thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ thread_wdctl(void *arg)
114114
if (-1 == bind(wdctl_socket_server, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
115115
debug(LOG_ERR, "Could not bind control socket: %s",
116116
strerror(errno));
117+
close(wdctl_socket_server);
117118
pthread_exit(NULL);
118119
}
119120

120121
if (listen(wdctl_socket_server, 5)) {
121122
debug(LOG_ERR, "Could not listen on control socket: %s",
122123
strerror(errno));
124+
close(wdctl_socket_server);
123125
pthread_exit(NULL);
124126
}
125127

@@ -305,11 +307,13 @@ wdctl_restart(int afd)
305307
/* Which to use, AF_UNIX, PF_UNIX, AF_LOCAL, PF_LOCAL? */
306308
if (-1 == bind(sock, (struct sockaddr *)&sa_un, sizeof(struct sockaddr_un))) {
307309
debug(LOG_ERR, "Could not bind internal socket: %s", strerror(errno));
310+
close(sock);
308311
return;
309312
}
310313

311314
if (listen(sock, 5)) {
312315
debug(LOG_ERR, "Could not listen on internal socket: %s", strerror(errno));
316+
close(sock);
313317
return;
314318
}
315319

0 commit comments

Comments
 (0)