aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorY. T. Chung <zonyitoo@gmail.com>2017-07-21 21:40:29 +0800
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-07-22 07:46:30 -0700
commitaa6c2821374f6dd6ed2e628c06bc08b0c4bc485c (patch)
treeec32a69e8d2c4a8c7fb4b48064637dd74c10d008
parente215a7bc18a2c3263a6fcca37c1ec53af6c4babd (diff)
downloadplatform_external_jemalloc_new-aa6c2821374f6dd6ed2e628c06bc08b0c4bc485c.tar.gz
platform_external_jemalloc_new-aa6c2821374f6dd6ed2e628c06bc08b0c4bc485c.tar.bz2
platform_external_jemalloc_new-aa6c2821374f6dd6ed2e628c06bc08b0c4bc485c.zip
Validates fd before calling fcntl
-rw-r--r--src/pages.c12
-rw-r--r--src/prof.c4
2 files changed, 12 insertions, 4 deletions
diff --git a/src/pages.c b/src/pages.c
index 0883647b..f8ef2bcb 100644
--- a/src/pages.c
+++ b/src/pages.c
@@ -358,7 +358,9 @@ os_overcommits_proc(void) {
O_CLOEXEC);
#else
fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY);
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ if (fd != -1) {
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
#endif
#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat)
#if defined(O_CLOEXEC)
@@ -367,14 +369,18 @@ os_overcommits_proc(void) {
#else
fd = (int)syscall(SYS_openat,
AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY);
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ if (fd != -1) {
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
#endif
#else
#if defined(O_CLOEXEC)
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY | O_CLOEXEC);
#else
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ if (fd != -1) {
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
#endif
#endif
diff --git a/src/prof.c b/src/prof.c
index a1ca9e2c..32760e68 100644
--- a/src/prof.c
+++ b/src/prof.c
@@ -1414,7 +1414,9 @@ prof_open_maps(const char *format, ...) {
mfd = open(filename, O_RDONLY | O_CLOEXEC);
#else
mfd = open(filename, O_RDONLY);
- fcntl(mfd, F_SETFD, fcntl(mfd, F_GETFD) | FD_CLOEXEC);
+ if (mfd != -1) {
+ fcntl(mfd, F_SETFD, fcntl(mfd, F_GETFD) | FD_CLOEXEC);
+ }
#endif
return mfd;