arduino-libraries / ArduinoBLE

ArduinoBLE library for Arduino
GNU Lesser General Public License v2.1
291 stars 198 forks source link

Fix UUID String Handling in BLEUuid Class #348

Open Mankianer opened 5 months ago

Mankianer commented 5 months ago

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.

CLAassistant commented 5 months ago

CLA assistant check
All committers have signed the CLA.