sharedmem.cpp: replace dup() with fcntl(F_DUPFD_CLOEXEC)

Replace calls to dup() with fcntl(F_DUPFD_CLOEXEC). The only difference
between the two is that O_CLOEXEC is set on the newly duped file
descriptor. This helps address file descriptor leaks crossing an exec()
boundary.

Test: compiles and boots
Change-Id: I95218331382b7a3432d31a46c173009dc4df1a6b
This commit is contained in:
Nick Kralevich
2019-01-14 13:52:43 -08:00
parent 7ae295368d
commit 396497085a

View File

@@ -71,7 +71,7 @@ int ASharedMemory_dupFromJava(JNIEnv* env, jobject javaSharedMemory) {
}
int fd = env->CallIntMethod(javaSharedMemory, sSharedMemory.getFd);
if (fd != -1) {
fd = dup(fd);
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
}
return fd;
}