diff options
author | Spencer Low <CompareAndSwap@gmail.com> | 2015-04-22 17:59:56 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-05-13 22:24:18 -0700 |
commit | b7a25286026b49f0f7d95b25f2d32c4f47f498ef (patch) | |
tree | 385e662d10838a2e6421b4229349a28572097d55 | |
parent | 32bd639dff4bf5bdddca8942f6984164859811dd (diff) | |
download | android_libnativehelper-stable/cm-13.0-ZNH2K.tar.gz android_libnativehelper-stable/cm-13.0-ZNH2K.tar.bz2 android_libnativehelper-stable/cm-13.0-ZNH2K.zip |
ScopedFd: Don't use TEMP_FAILURE_RETRY() with close()HEADreplicant-6.0-0004-transitionreplicant-6.0-0004-rc6replicant-6.0-0004-rc5-transitionreplicant-6.0-0004-rc5replicant-6.0-0004-rc4replicant-6.0-0004-rc3replicant-6.0-0004-rc2replicant-6.0-0004-rc1replicant-6.0-0004replicant-6.0-0003replicant-6.0-0002replicant-6.0-0001stable/cm-13.0-ZNH5Ystable/cm-13.0-ZNH2KBstable/cm-13.0-ZNH2Kstable/cm-13.0-ZNH0Ecm-13.0
According to the comments in Posix_close(), TEMP_FAILURE_RETRY() should
not be used with close():
https://android.googlesource.com/platform/libcore/+/462bdac45c10f43d88d8f07f6994e272a27c14a2%5E%21/#F12
Bug: http://b/20501816
Change-Id: Ie283f848c4fe50fcde9358c8ed307ec048e70892
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
(cherry picked from commit 315ac19f69d5ca232ddc4a73b4d4088ac6c65e47)
-rw-r--r-- | include/nativehelper/ScopedFd.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/include/nativehelper/ScopedFd.h b/include/nativehelper/ScopedFd.h index 5ef41f8..d14e62b 100644 --- a/include/nativehelper/ScopedFd.h +++ b/include/nativehelper/ScopedFd.h @@ -18,7 +18,7 @@ #define SCOPED_FD_H_included #include <unistd.h> -#include "JNIHelp.h" // for TEMP_FAILURE_RETRY +#include "JNIHelp.h" // for DISALLOW_COPY_AND_ASSIGN. // A smart pointer that closes the given fd on going out of scope. // Use this when the fd is incidental to the purpose of your function, @@ -44,7 +44,10 @@ public: void reset(int new_fd = -1) { if (fd_ != -1) { - TEMP_FAILURE_RETRY(close(fd_)); + // Even if close(2) fails with EINTR, the fd will have been closed. + // Using TEMP_FAILURE_RETRY will either lead to EBADF or closing someone else's fd. + // http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html + close(fd_); } fd_ = new_fd; } |