Skip to content

Commit

Permalink
Merge pull request #7 from Sensirion/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak
  • Loading branch information
psachs authored Oct 25, 2024
2 parents b74d2df + bed28e9 commit f1cf4ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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

0 comments on commit f1cf4ab

Please sign in to comment.