OSDN Git Service

Bitmap.cpp: replace dup() with fcntl(F_DUPFD_CLOEXEC)
authorNick Kralevich <nnk@google.com>
Mon, 14 Jan 2019 21:42:22 +0000 (13:42 -0800)
committerNick Kralevich <nnk@google.com>
Mon, 14 Jan 2019 21:42:22 +0000 (13:42 -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.

Test: compiles and boots
Change-Id: I0c3b1baa49677a8e4831e1880e2d0ab38e08c6f4

core/jni/android/graphics/Bitmap.cpp

index b085bc9..b6fbb0a 100755 (executable)
@@ -1095,7 +1095,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
 #endif
         // Dup the file descriptor so we can keep a reference to it after the Parcel
         // is disposed.
-        int dupFd = dup(blob.fd());
+        int dupFd = fcntl(blob.fd(), F_DUPFD_CLOEXEC, 0);
         if (dupFd < 0) {
             ALOGE("Error allocating dup fd. Error:%d", errno);
             blob.release();