-
Notifications
You must be signed in to change notification settings - Fork 217
Bugfix: memory leak caused by variables not being deleted in end() #237
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
Conversation
This will crash the board on Arduino Uno Wifi Rev2. At first I thought it worked because the memory was freed, but it was only because the board resets and starts all over (observable by logging something in It does not reset in the current Minimal reproduction sketch
Output with this PR:
Output in `master`:
|
Hi @buffcode , #ifdef __MBED__
#include <mbed.h>
#include <mbed_mem_trace.h>
#else
#include <MemoryFree.h>
#endif
#include <ArduinoBLE.h>
#ifdef __MBED__
REDIRECT_STDOUT_TO(Serial)
void print_memory_info() {
// allocate enough room for every thread's stack statistics
int cnt = osThreadGetCount();
mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));
cnt = mbed_stats_stack_get_each(stats, cnt);
for (int i = 0; i < cnt; i++) {
printf("Thread: 0x%lX, Stack size: %lu / %lu\r\n", stats[i].thread_id, stats[i].max_size, stats[i].reserved_size);
}
free(stats);
// Grab the heap statistics
mbed_stats_heap_t heap_stats;
mbed_stats_heap_get(&heap_stats);
printf("Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
}
#else
void print_memory_info() {
Serial.println(freeMemory());
}
#endif
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("===================");
Serial.println("Setup, you should only see this once");
Serial.println("===================");
}
void loop() {
print_memory_info();
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// start scanning for peripheral
Serial.println("starting Bluetooth® Low Energy scan");
BLE.scan();
BLE.stopScan();
Serial.println("BLE.end");
BLE.end();
} |
Hi @buffcode I tried release 1.3.0 and your test code above on the Artemis Redboard (uses Apollo3 chipset) and got the same crash as before. I'm running this release of the Sparkfun Apollo3 board: https://github.com/sparkfun/Arduino_Apollo3/releases/tag/v2.2.1 A couple things about my test...
|
This pull request addresses the issue described in #192 caused by variables initialized in begin() not being deleted in end(). This leads to hangs and crashes reported also in other issues.