From 8238dd84992988ecbaa8b8e2b5691d2cf2391e35 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 4 Mar 2016 17:50:10 -0800 Subject: [PATCH] adbd: fix spurious close of uninitialized fd. forkpty only returns an fd on the master side; trying to keep track of it on both sides is incorrect. Bug: http://b/27504427 Change-Id: Ia4a454d8490c77738f9c3350a4236b3d99c8758b (cherry picked from commit fcb063ce378419ad1511d3395d44701b4ebaceb0) --- adb/shell_service.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp index 95fd49b74..ce107084c 100644 --- a/adb/shell_service.cpp +++ b/adb/shell_service.cpp @@ -284,7 +284,9 @@ bool Subprocess::ForkAndExec(std::string* error) { if (type_ == SubprocessType::kPty) { int fd; pid_ = forkpty(&fd, pts_name, nullptr, nullptr); - stdinout_sfd_.Reset(fd); + if (pid_ > 0) { + stdinout_sfd_.Reset(fd); + } } else { if (!CreateSocketpair(&stdinout_sfd_, &child_stdinout_sfd)) { *error = android::base::StringPrintf("failed to create socketpair for stdin/out: %s",