Skip to content

Fix UUID String Handling in BLEUuid Class#348

Open
Mankianer wants to merge 2 commits intoarduino-libraries:masterfrom
Mankianer:mankianer/fix-uuid-string-copy
Open

Fix UUID String Handling in BLEUuid Class#348
Mankianer wants to merge 2 commits intoarduino-libraries:masterfrom
Mankianer:mankianer/fix-uuid-string-copy

Conversation

@Mankianer
Copy link

This pull request addresses a critical issue in the BLEUuid class where the UUID string was not being properly managed. The class was storing a pointer to the original string passed to it, which could lead to unexpected behavior if the original string was modified or went out of scope.

Changes made:

  1. The _str member of the BLEUuid class has been changed from a const char* to a char*. This allows us to modify the pointer and point it to a new string copy.
  2. In the BLEUuid constructor, we now create a copy of the string passed using the strdup function. This ensures that the BLEUuid class has its own copy of the UUID string, which remains valid even if the original string changes or goes out of scope.
  3. In the BLEUuid destructor, we free the memory allocated for the string copy. This prevents memory leaks when BLEUuid objects are destroyed.

These changes ensure that the BLEUuid class correctly manages its own copy of the UUID string, preventing potential issues caused by changes to the original string. This makes the BLEUuid class more robust and reliable in its handling of UUID strings.

This commit addresses an issue in the BLEUuid class where the UUID string was not being properly copied. Previously, the class stored a pointer to the original string, which could lead to issues if the original string was modified or went out of scope.

The fix involves changing the _str member of the BLEUuid class to be a non-const char pointer, and using the strdup function to create a copy of the string in the BLEUuid constructor. The destructor of the BLEUuid class has also been updated to free the memory allocated for the string copy.

This change ensures that the BLEUuid class has its own copy of the UUID string, preventing potential issues caused by changes to the original string.

Signed-off-by: Mankianer <mankianer@gmail.com>
@CLAassistant
Copy link

CLAassistant commented Feb 1, 2024

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Feb 1, 2024
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Memory usage change @ b0edfc0

Board flash % RAM for global variables %
arduino:esp32:nano_nora 🔺 +236 - +244 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_giga:giga 🔺 +128 - +192 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 🔺 +128 - +192 +0.01 - +0.02 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 +134 - +134 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nicla:nicla_vision 🔺 +128 - +192 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +192 - +192 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:megaavr:uno2018:mode=on 🔺 +154 - +154 +0.32 - +0.32 0 - 0 0.0 - 0.0
arduino:renesas_portenta:portenta_c33 🔺 +136 - +144 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:renesas_uno:unor4wifi 🔺 +136 - +152 +0.05 - +0.06 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 🔺 +136 - +144 +0.05 - +0.05 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 🔺 +136 - +144 +0.05 - +0.05 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Central/LedControl
flash
% examples/Central/LedControl
RAM for global variables
% examples/Central/PeripheralExplorer
flash
% examples/Central/PeripheralExplorer
RAM for global variables
% examples/Central/Scan
flash
% examples/Central/Scan
RAM for global variables
% examples/Central/ScanCallback
flash
% examples/Central/ScanCallback
RAM for global variables
% examples/Central/SensorTagButton
flash
% examples/Central/SensorTagButton
RAM for global variables
% examples/Peripheral/Advertising/EnhancedAdvertising
flash
% examples/Peripheral/Advertising/EnhancedAdvertising
RAM for global variables
% examples/Peripheral/Advertising/RawDataAdvertising
flash
% examples/Peripheral/Advertising/RawDataAdvertising
RAM for global variables
% examples/Peripheral/BatteryMonitor
flash
% examples/Peripheral/BatteryMonitor
RAM for global variables
% examples/Peripheral/ButtonLED
flash
% examples/Peripheral/ButtonLED
RAM for global variables
% examples/Peripheral/CallbackLED
flash
% examples/Peripheral/CallbackLED
RAM for global variables
% examples/Peripheral/EncryptedBatteryMonitor
flash
% examples/Peripheral/EncryptedBatteryMonitor
RAM for global variables
% examples/Peripheral/LED
flash
% examples/Peripheral/LED
RAM for global variables
%
arduino:esp32:nano_nora 236 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 240 0.01 0 0.0 244 0.01 0 0.0 236 0.01 0 0.0
arduino:mbed_giga:giga 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 128 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0
arduino:mbed_nano:nano33ble 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 192 0.02 0 0.0 128 0.01 0 0.0 128 0.01 0 0.0 192 0.02 0 0.0 192 0.02 0 0.0
arduino:mbed_nano:nanorp2040connect 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0 134 0.0 0 0.0
arduino:mbed_nicla:nicla_vision 128 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 128 0.01 0 0.0
arduino:mbed_opta:opta 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0 192 0.01 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:megaavr:uno2018:mode=on 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0 154 0.32 0 0.0
arduino:renesas_portenta:portenta_c33 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0 144 0.01 0 0.0 144 0.01 0 0.0 136 0.01 0 0.0 136 0.01 0 0.0
arduino:renesas_uno:unor4wifi 152 0.06 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 152 0.06 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 152 0.06 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 152 0.06 0 0.0
arduino:samd:mkrwifi1010 136 0.05 0 0.0 144 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0
arduino:samd:nano_33_iot 136 0.05 0 0.0 144 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0 136 0.05 0 0.0
Click for full report CSV
Board,examples/Central/LedControl<br>flash,%,examples/Central/LedControl<br>RAM for global variables,%,examples/Central/PeripheralExplorer<br>flash,%,examples/Central/PeripheralExplorer<br>RAM for global variables,%,examples/Central/Scan<br>flash,%,examples/Central/Scan<br>RAM for global variables,%,examples/Central/ScanCallback<br>flash,%,examples/Central/ScanCallback<br>RAM for global variables,%,examples/Central/SensorTagButton<br>flash,%,examples/Central/SensorTagButton<br>RAM for global variables,%,examples/Peripheral/Advertising/EnhancedAdvertising<br>flash,%,examples/Peripheral/Advertising/EnhancedAdvertising<br>RAM for global variables,%,examples/Peripheral/Advertising/RawDataAdvertising<br>flash,%,examples/Peripheral/Advertising/RawDataAdvertising<br>RAM for global variables,%,examples/Peripheral/BatteryMonitor<br>flash,%,examples/Peripheral/BatteryMonitor<br>RAM for global variables,%,examples/Peripheral/ButtonLED<br>flash,%,examples/Peripheral/ButtonLED<br>RAM for global variables,%,examples/Peripheral/CallbackLED<br>flash,%,examples/Peripheral/CallbackLED<br>RAM for global variables,%,examples/Peripheral/EncryptedBatteryMonitor<br>flash,%,examples/Peripheral/EncryptedBatteryMonitor<br>RAM for global variables,%,examples/Peripheral/LED<br>flash,%,examples/Peripheral/LED<br>RAM for global variables,%
arduino:esp32:nano_nora,236,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,240,0.01,0,0.0,244,0.01,0,0.0,236,0.01,0,0.0
arduino:mbed_giga:giga,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,128,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0
arduino:mbed_nano:nano33ble,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,192,0.02,0,0.0,128,0.01,0,0.0,128,0.01,0,0.0,192,0.02,0,0.0,192,0.02,0,0.0
arduino:mbed_nano:nanorp2040connect,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0,134,0.0,0,0.0
arduino:mbed_nicla:nicla_vision,128,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,128,0.01,0,0.0
arduino:mbed_opta:opta,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0,192,0.01,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A
arduino:megaavr:uno2018:mode=on,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0,154,0.32,0,0.0
arduino:renesas_portenta:portenta_c33,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0,144,0.01,0,0.0,144,0.01,0,0.0,136,0.01,0,0.0,136,0.01,0,0.0
arduino:renesas_uno:unor4wifi,152,0.06,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,152,0.06,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,152,0.06,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,152,0.06,0,0.0
arduino:samd:mkrwifi1010,136,0.05,0,0.0,144,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0
arduino:samd:nano_33_iot,136,0.05,0,0.0,144,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0,136,0.05,0,0.0

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 15.38%. Comparing base (2beed7b) to head (b0edfc0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #348      +/-   ##
==========================================
+ Coverage   15.26%   15.38%   +0.11%     
==========================================
  Files          29       29              
  Lines        3681     3686       +5     
==========================================
+ Hits          562      567       +5     
  Misses       3119     3119              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

3 participants