Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ArduinoBLE crashes when BLE.begin BLE.end is called multiple times (possible solution included) #192

Closed
Assignees
Labels
conclusion: resolvedIssue was resolved topic: codeRelated to content of the project itself type: imperfectionPerceived defect in any part of project
@Klaus-KK

Description

The issue was reported by a user in the Arduino forum, who wants to switch between BLE and WiFi on a regular basis.

https://forum.arduino.cc/t/repeated-ble-begin-end-crashes-board/885009

I wrote the following sketch for testing and it crashes after 50 loops.

#include <ArduinoBLE.h>
void setup()
{
 Serial.begin( 9600 );
 while ( !Serial );
 Serial.println( "ArduinoBLE memory leak test" );
}
void loop()
{
 static uint32_t counter = 0;
 BLE.begin();
 counter++;
 Serial.print( "C: " );
 Serial.println( counter );
 BLE.end();
}

With my limited C++ knowledge I found in void GATTClass::begin() a couple of objects are created with new. They are not deleted in void GATTClass::end().

Adding the 5 deletes to GATTClass::end seems to fix the issue. Can you confirm this is the right way to fix this and implement this in the next version of the library?

void GATTClass::end()
{
 delete( _genericAccessService );
 delete( _deviceNameCharacteristic );
 delete( _appearanceCharacteristic );
 delete( _genericAttributeService );
 delete( _servicesChangedCharacteristic );
 _attributes.clear();
}

Metadata

Metadata

Assignees

Labels

conclusion: resolvedIssue was resolved topic: codeRelated to content of the project itself type: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /