From bae5b1dbd8dfe7318e208be917f4c9b9e8abced6 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Wed, 2 Jul 2014 22:39:14 -0700 Subject: [PATCH] libc_logging: Set SOCK_CLOEXEC on socket Socket file descriptors remain open across exec unless SOCK_CLOEXEC is set. Enable this option, to avoid leaking file descriptors. In practice, this isn't a big deal, since the socket only remains open for a very short period to write a message. However, this socket might leak for for multithreaded programs if an exec occurs between the open and close. Change-Id: Ica2e71fe28657c32d56de1431c8f7f1f5c7b7c58 --- libc/bionic/libc_logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp index 8b3d3f1fc..e656a1255 100644 --- a/libc/bionic/libc_logging.cpp +++ b/libc/bionic/libc_logging.cpp @@ -453,7 +453,7 @@ static int __libc_open_log_socket() // found that all logd crashes thus far have had no problem stuffing // the UNIX domain socket and moving on so not critical *today*. - int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM, 0)); + int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)); if (log_fd < 0) { return -1; }