diff options
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
| -rw-r--r-- | libs/binder/IPCThreadState.cpp | 12 | 
1 files changed, 10 insertions, 2 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 1f6bda2a94..1cbcfe4de5 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -1089,8 +1089,16 @@ status_t IPCThreadState::executeCommand(int32_t cmd)                      << reinterpret_cast<const size_t*>(tr.data.ptr.offsets) << endl;              }              if (tr.target.ptr) { -                sp<BBinder> b((BBinder*)tr.cookie); -                error = b->transact(tr.code, buffer, &reply, tr.flags); +                // We only have a weak reference on the target object, so we must first try to +                // safely acquire a strong reference before doing anything else with it. +                if (reinterpret_cast<RefBase::weakref_type*>( +                        tr.target.ptr)->attemptIncStrong(this)) { +                    error = reinterpret_cast<BBinder*>(tr.cookie)->transact(tr.code, buffer, +                            &reply, tr.flags); +                    reinterpret_cast<BBinder*>(tr.cookie)->decStrong(this); +                } else { +                    error = UNKNOWN_TRANSACTION; +                }              } else {                  error = the_context_object->transact(tr.code, buffer, &reply, tr.flags);  |