esp32-snippets: Memory leak in BLECharacteristic::notify()

The call to m_value.getValue().length() to log the message length in BLECharacteristic::notify() is causing an 84 byte memory leak. I’ve added extra log statements, logging the ESP.getFreeHeap() value before and after that call (and in the method calling notify() and this is the result:

[D][BLEObserver.cpp:35] notification(): Free memory Master before notify(): 66524 [D][BLECharacteristic.cpp:485] notify(): Free memory on notify()::Enter : 66524 [D][BLECharacteristic.cpp:486] notify(): >> notify: length: 10 [D][BLECharacteristic.cpp:487] notify(): Free memory on notify(), After LOGD m_value.getValue().length(): 66440 [D][BLECharacteristic.cpp:495] notify(): << notify: No connected clients. [D][BLEObserver.cpp:37] notification(): Free memory Master after notify(): 66440

This occurs with every call of notify, eventually draining all resources

I’m assuming that this has something to do with the way the std::string m_Value is returned by getValue() method. I tried replacing m_value.getValue().length() with m_value_getLength() but with the same results

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 26

Most upvoted comments

I am a little busy now, but i will try to find it. As you can see i could not recreate memory leak, but with your settings i will perform more tests.

Ok, that might solve it I do think you should also add the delete statement before the other return statements in that method btw