Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If something within BLELocalDevice::begin() fail calls to end will fault #324

Open
KurtE opened this issue Sep 6, 2023 · 0 comments
Open
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@KurtE
Copy link

KurtE commented Sep 6, 2023

In the case that I was debugging, I am testing running the library on top of the USBHost_t36 code on Teensy 3.6 or 4.x.

It works with some Bluetooth dongles and not others. In the case I am debugging it faults when I use a CSR 4.0 dongle.

I traced it to the call:

  if (HCI.setLeEventMask(0x00000000000003FF) != 0) {
    end();
    return 0;
  }

It failed with error code 0x12.

The call to end() ends up faulting.

The reason GATT.begin();
has not been called. It is called near the end of the BLELocalDevice::begin() ,

And BLELocalDevice::end() calls GATT.end.

void BLELocalDevice::end()
{
  GATT.end();
...

And GAT.end() calls off and deletes objects which have not yet been created.

void GATTClass::end()
{
  if (_genericAccessService->release() == 0)
    delete(_genericAccessService);
  
  if (_deviceNameCharacteristic->release() == 0)
    delete(_deviceNameCharacteristic);
  
  if (_appearanceCharacteristic->release() == 0)
    delete(_appearanceCharacteristic);
  
  if (_genericAttributeService->release() == 0)
    delete(_genericAttributeService);
  
  if (_servicesChangedCharacteristic->release() == 0)
    delete(_servicesChangedCharacteristic);
  
  clearAttributes();
}

Possible fixes:

  1. Don't call GATT.end() if begin has not yet been called.
  2. Change the GATT code to check before calling...
    like:
  if (_genericAccessService && (_genericAccessService->release() == 0))
    delete(_genericAccessService);

Wondering if is the same issue, that is mentioned in #273

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants