Merge "adbd: fix spurious close of uninitialized fd." am: 3c608c7425 am: 97b9935fba
am: f5b960538f
* commit 'f5b960538f95c5b42f97595bc1325fffa0e591f1':
adbd: fix spurious close of uninitialized fd.
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index f84447f..8ece28c 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -315,7 +315,9 @@
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",