enable SOCK_CLOEXEC explicit

leaking here means fork/vfork will duplicate fd without O_CLOEXEC flag
to the child process.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
This commit is contained in:
wanggang26 2023-11-24 10:44:50 +08:00 • committed by Xiang Xiao
parent 3f0c9306d3
commit eab2cba4a1
20 changed files with 56 additions and 30 deletions

View file

@ -92,7 +92,8 @@ void netlib_server(uint16_t portno,
/* Accept the next connection */
addrlen = sizeof(struct sockaddr_in);
acceptsd = accept(listensd, (struct sockaddr *)&myaddr, &addrlen);
acceptsd = accept4(listensd, (struct sockaddr *)&myaddr, &addrlen,
SOCK_CLOEXEC);
if (acceptsd < 0)
{
nerr("ERROR: accept failure: %d\n", errno);