aboutsummaryrefslogtreecommitdiff
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)
downloadlibnativehelper-android-6.0.0_r41.tar.gz
ScopedFd: Don't use TEMP_FAILURE_RETRY() with close()android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1afw-test-harness-1.5marshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-release
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;
}