mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Check more setsockopt return values when binding sockets. Found by coverity
This commit is contained in:
parent
a1a0e67531
commit
a0912e3206
9
http.c
9
http.c
@ -3825,9 +3825,12 @@ bind_socket_ai(struct evutil_addrinfo *ai, int reuse)
|
|||||||
if (evutil_make_socket_closeonexec(fd) < 0)
|
if (evutil_make_socket_closeonexec(fd) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on))<0)
|
||||||
if (reuse)
|
goto out;
|
||||||
evutil_make_listen_socket_reuseable(fd);
|
if (reuse) {
|
||||||
|
if (evutil_make_listen_socket_reuseable(fd) < 0)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (ai != NULL) {
|
if (ai != NULL) {
|
||||||
r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen);
|
r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen);
|
||||||
|
10
listener.c
10
listener.c
@ -226,9 +226,15 @@ evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on));
|
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0) {
|
||||||
|
evutil_closesocket(fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (flags & LEV_OPT_REUSEABLE) {
|
if (flags & LEV_OPT_REUSEABLE) {
|
||||||
evutil_make_listen_socket_reuseable(fd);
|
if (evutil_make_listen_socket_reuseable(fd) < 0) {
|
||||||
|
evutil_closesocket(fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa) {
|
if (sa) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user