OSDN Git Service

replace dup() with fcntl(F_DUPFD_CLOEXEC)
authorNick Kralevich <nnk@google.com>
Mon, 14 Jan 2019 18:37:01 +0000 (10:37 -0800)
committerNick Kralevich <nnk@google.com>
Mon, 14 Jan 2019 18:37:01 +0000 (10:37 -0800)
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 in multi-threaded processes

Test: compiles and boots
Change-Id: I6b82a7932593a5e39880fcf3ff6443dab6500094

core/jni/android_os_Parcel.cpp

index 7ef06dc..3b59321 100644 (file)
@@ -473,7 +473,7 @@ static jobject android_os_Parcel_readFileDescriptor(JNIEnv* env, jclass clazz, j
     if (parcel != NULL) {
         int fd = parcel->readFileDescriptor();
         if (fd < 0) return NULL;
-        fd = dup(fd);
+        fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
         if (fd < 0) return NULL;
         return jniCreateFileDescriptor(env, fd);
     }