OSDN Git Service

Use weak pointer when refering to AdvertisingManager
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 25 Jan 2018 18:53:57 +0000 (10:53 -0800)
committerJakub Pawlowski <jpawlowski@google.com>
Fri, 26 Jan 2018 07:07:55 +0000 (23:07 -0800)
commitce0d65f4b96fd5d0dd53d998bea758874a37503e
tree04f1ed351afe1c504a39dcd69a57af373871c606
parent935513cbaba66ca1f7ace95f11a8646f5608763e
Use weak pointer when refering to AdvertisingManager

In btif layer, we schedule tasks for execution on
AdvertisingManager on bta thread. Before the scheduling we check if
AdvertisingManager is initialized. We don't check if AdvertisingManager
is still valid, when the command execution is starting on the bta thread.
This is a race condition, that can cause crashes.

To fix that, always post task for execution using weak reference, rather
than raw pointer. Thanks to it, the MessageLoop will check if the
weak_ptr is valid before attempt to execute the task. The check happens
on the target thread, right before the execution, eliminating all
possible race conditions.

Test: ran all advertising tests, no regression
Bug: 71051865
Change-Id: I7fd8255879d5272d47aa79974bb79bdaacb55800
btif/src/btif_ble_advertiser.cc
btif/src/btif_core.cc
stack/btm/btm_ble_multi_adv.cc
stack/include/ble_advertiser.h