aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Low <CompareAndSwap@gmail.com>2015-04-22 17:59:56 -0700
committerElliott Hughes <enh@google.com>2015-05-13 22:24:18 -0700
commitb7a25286026b49f0f7d95b25f2d32c4f47f498ef (patch)
tree385e662d10838a2e6421b4229349a28572097d55
parent32bd639dff4bf5bdddca8942f6984164859811dd (diff)
downloadandroid_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
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.h7
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;
}