From 10d090aae9834e1eb24b957d4fac042c205af52e Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 30 May 2017 14:36:55 -0700 Subject: [PATCH] Pass the O_CLOEXEC flag to open(2). This resolves #528. --- src/pages.c | 7 ++++--- src/prof.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages.c b/src/pages.c index 3a048e3b..fec64dd0 100644 --- a/src/pages.c +++ b/src/pages.c @@ -353,12 +353,13 @@ os_overcommits_proc(void) { ssize_t nread; #if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open) - fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY); + fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY | + O_CLOEXEC); #elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat) fd = (int)syscall(SYS_openat, - AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY); + AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY | O_CLOEXEC); #else - fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY); + fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY | O_CLOEXEC); #endif if (fd == -1) { return false; /* Error. */ diff --git a/src/prof.c b/src/prof.c index 639e5983..aa67486d 100644 --- a/src/prof.c +++ b/src/prof.c @@ -1409,7 +1409,7 @@ prof_open_maps(const char *format, ...) { va_start(ap, format); malloc_vsnprintf(filename, sizeof(filename), format, ap); va_end(ap); - mfd = open(filename, O_RDONLY); + mfd = open(filename, O_RDONLY | O_CLOEXEC); return mfd; }