Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb192451 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Fix crashes on stack shutdown

During stack shutdown, Unregister would sometimes get called after the
stack is already cleaned up, and the AdvertiseManager::Get would crash
on null check assertion. Ensure that stack is initialized before
Unregister call.

Bug: 37888261
Test: none
Change-Id: I7a4bbcd24ec7d24d21d04fe842985baaac899321
parent 6eb34cca
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -103,8 +103,15 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface {
  void Unregister(uint8_t advertiser_id) override {
    do_in_bta_thread(
        FROM_HERE,
        Bind(&BleAdvertisingManager::Unregister,
             base::Unretained(BleAdvertisingManager::Get()), advertiser_id));
        Bind(
            [](uint8_t advertiser_id) {
              if (!BleAdvertisingManager::IsInitialized()) {
                LOG(WARNING) << "Stack already shutdown";
                return;
              }
              BleAdvertisingManager::Get()->Unregister(advertiser_id);
            },
            advertiser_id));
  }

  void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) override {
+2 −0
Original line number Diff line number Diff line
@@ -868,6 +868,8 @@ void BleAdvertisingManager::Initialize(BleAdvertiserHciInterface* interface) {
  instance = new BleAdvertisingManagerImpl(interface);
}

bool BleAdvertisingManager::IsInitialized() { return instance; }

BleAdvertisingManager* BleAdvertisingManager::Get() {
  CHECK(instance);
  return instance;
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ class BleAdvertisingManager {

  static void Initialize(BleAdvertiserHciInterface* interface);
  static void CleanUp();
  static bool IsInitialized();
  static BleAdvertisingManager* Get();

  /* Register an advertising instance, status will be returned in |cb|