From ea3f07b614a5704a7e4c3ab3c8ccc8f994904ea1 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Tue, 12 Dec 2017 21:51:40 -0800 Subject: [PATCH] cas: manually clear strong ref before callback Hidl doesn't guarantee the server side method goes out of scope before the client side returns. Even when client calls on the same thread, the next method could overlap the previous call. Next call can come in as soon as the hidl callback is called. In case of openSession and release, there is a rare chance that release call comes in before previous openSession is returned. If this happens, the cas plugin object destructor is delayed to the point when openSession goes out of scope (thus let go its strong ref to the plugin). This violates our contract that the plugin object and all associated sessions are released by the time release() returns. Manually clean up the strong ref before calling hidl callback in openSession would fix this. bug: 70544685 Change-Id: Id89a00591a354c8a46def3cc691dd8e28b4c971b --- cas/1.0/default/CasImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cas/1.0/default/CasImpl.cpp b/cas/1.0/default/CasImpl.cpp index 9d1f4a3268..2ac1c4f6dd 100644 --- a/cas/1.0/default/CasImpl.cpp +++ b/cas/1.0/default/CasImpl.cpp @@ -103,6 +103,7 @@ Return CasImpl::openSession(openSession_cb _hidl_cb) { status_t err = INVALID_OPERATION; if (holder != NULL) { err = holder->get()->openSession(&sessionId); + holder.clear(); } _hidl_cb(toStatus(err), sessionId);