Validates fd before calling fcntl
This commit is contained in:
parent
e215a7bc18
commit
aa6c282137
@ -358,7 +358,9 @@ os_overcommits_proc(void) {
|
|||||||
O_CLOEXEC);
|
O_CLOEXEC);
|
||||||
#else
|
#else
|
||||||
fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY);
|
fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY);
|
||||||
|
if (fd != -1) {
|
||||||
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat)
|
#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat)
|
||||||
#if defined(O_CLOEXEC)
|
#if defined(O_CLOEXEC)
|
||||||
@ -367,14 +369,18 @@ os_overcommits_proc(void) {
|
|||||||
#else
|
#else
|
||||||
fd = (int)syscall(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);
|
||||||
|
if (fd != -1) {
|
||||||
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if defined(O_CLOEXEC)
|
#if defined(O_CLOEXEC)
|
||||||
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY | O_CLOEXEC);
|
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY | O_CLOEXEC);
|
||||||
#else
|
#else
|
||||||
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
|
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
|
||||||
|
if (fd != -1) {
|
||||||
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1414,7 +1414,9 @@ prof_open_maps(const char *format, ...) {
|
|||||||
mfd = open(filename, O_RDONLY | O_CLOEXEC);
|
mfd = open(filename, O_RDONLY | O_CLOEXEC);
|
||||||
#else
|
#else
|
||||||
mfd = open(filename, O_RDONLY);
|
mfd = open(filename, O_RDONLY);
|
||||||
|
if (mfd != -1) {
|
||||||
fcntl(mfd, F_SETFD, fcntl(mfd, F_GETFD) | FD_CLOEXEC);
|
fcntl(mfd, F_SETFD, fcntl(mfd, F_GETFD) | FD_CLOEXEC);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mfd;
|
return mfd;
|
||||||
|
Loading…
Reference in New Issue
Block a user