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

Fix memory leak #7

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix memory leak in NimBLE by calling clearResults after scan results are processed.
- Use unit64_t for address (device id) instead of std::string
- Fix several clang tidy issues
- Update example to call keepAlive regularly. This ensures scanning does not stop due to errors.

## [0.1.0]
### Added
- Initial release
Expand Down
5 changes: 4 additions & 1 deletion examples/GetLiveValues/GetLiveValues.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ void setup() {

void loop() {
std::map<uint16_t, std::vector<Measurement>> scanResults;

delay(1000);

sensiScan.getScanResults(scanResults);

printScanResults(scanResults);

// ensure scanning is restarted in case of errors.
sensiScan.keepAlive();
}

void printScanResults(
Expand Down
3 changes: 3 additions & 0 deletions src/NimBleClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ void NimBleClient::onResult(NimBLEAdvertisedDevice* advertisedDevice) {
std::string manufacturerData = advertisedDevice->getManufacturerData();

_callback->onAdvertisementReceived(address, name, manufacturerData);

// clear NIMBle scan results to avoid memory leak.
_bleScan->clearResults();
}

void NimBleClient::setupBleScans() {
Expand Down