From a0f0bd930cfd2d607bf3d3288f46e2d265dd2e11 Mon Sep 17 00:00:00 2001 From: copercini Date: Mon, 27 Aug 2018 07:06:23 -0300 Subject: [PATCH] Fix BTserial memory leaks (#1801) - Delete queue at end - Close BT connection before end - DeInit SPP --- libraries/BluetoothSerial/src/BluetoothSerial.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index a71bd294..97f18867 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -152,6 +152,9 @@ static bool _init_bt(const char *deviceName) static bool _stop_bt() { if (btStarted()){ + if(_spp_client) + esp_spp_disconnect(_spp_client); + esp_spp_deinit(); esp_bluedroid_disable(); esp_bluedroid_deinit(); btStop(); @@ -172,6 +175,7 @@ BluetoothSerial::BluetoothSerial() BluetoothSerial::~BluetoothSerial(void) { _stop_bt(); + vQueueDelete(_spp_queue); } bool BluetoothSerial::begin(String localName) @@ -262,6 +266,7 @@ void BluetoothSerial::flush() void BluetoothSerial::end() { _stop_bt(); + vQueueDelete(_spp_queue); } #endif