From c65fae9ef56163d17bcc86b6b6324be2b56b4aa5 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 19 Jan 2016 16:21:17 -0800 Subject: [PATCH] adbd: don't leave zombies when subprocess creation fails. Bug: http://b/26660675 Change-Id: I8e65d51af73f409c30be47575f76bc6b0f227c54 --- adb/fdevent.cpp | 4 +++- adb/shell_service.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp index 25e8376a0..386f22186 100644 --- a/adb/fdevent.cpp +++ b/adb/fdevent.cpp @@ -306,12 +306,14 @@ static void fdevent_subproc_event_func(int fd, unsigned ev, auto it = g_poll_node_map.find(subproc_fd); if (it == g_poll_node_map.end()) { D("subproc_fd %d cleared from fd_table", subproc_fd); + adb_close(subproc_fd); return; } fdevent* subproc_fde = it->second.fde; if(subproc_fde->fd != subproc_fd) { // Already reallocated? - D("subproc_fd(%d) != subproc_fde->fd(%d)", subproc_fd, subproc_fde->fd); + LOG(FATAL) << "subproc_fd(" << subproc_fd << ") != subproc_fde->fd(" << subproc_fde->fd + << ")"; return; } diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp index 366ed074a..95dff117e 100644 --- a/adb/shell_service.cpp +++ b/adb/shell_service.cpp @@ -233,6 +233,7 @@ Subprocess::Subprocess(const std::string& command, const char* terminal_type, } Subprocess::~Subprocess() { + WaitForExit(); } bool Subprocess::ForkAndExec() { @@ -432,7 +433,6 @@ void* Subprocess::ThreadHandler(void* userdata) { "shell srvc %d", subprocess->local_socket_fd())); subprocess->PassDataStreams(); - subprocess->WaitForExit(); D("deleting Subprocess for PID %d", subprocess->pid()); delete subprocess;