diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 7a3a3b9f5..7e416b9d5 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -758,7 +758,9 @@ finish: status_t IPCThreadState::talkWithDriver(bool doReceive) { - ALOG_ASSERT(mProcess->mDriverFD >= 0, "Binder driver is not opened"); + if (mProcess->mDriverFD <= 0) { + return -EBADF; + } binder_write_read bwr; @@ -814,6 +816,9 @@ status_t IPCThreadState::talkWithDriver(bool doReceive) #else err = INVALID_OPERATION; #endif + if (mProcess->mDriverFD <= 0) { + err = -EBADF; + } IF_LOG_COMMANDS() { alog << "Finished read/write, write size = " << mOut.dataSize() << endl; } @@ -1106,7 +1111,9 @@ void IPCThreadState::threadDestructor(void *st) if (self) { self->flushCommands(); #if defined(HAVE_ANDROID_OS) - ioctl(self->mProcess->mDriverFD, BINDER_THREAD_EXIT, 0); + if (self->mProcess->mDriverFD > 0) { + ioctl(self->mProcess->mDriverFD, BINDER_THREAD_EXIT, 0); + } #endif delete self; }