Skip to content

Commit 3003f12

Browse files
authored
Merge pull request arduino-libraries#237 from alranel/bugfix/192-leak
Bugfix: memory leak caused by variables not being deleted in end()
2 parents f2f73e8 + afccc49 commit 3003f12

10 files changed

+32
-14
lines changed

src/BLECharacteristic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ BLECharacteristic::BLECharacteristic(const BLECharacteristic& other)
7272

7373
BLECharacteristic::~BLECharacteristic()
7474
{
75-
if (_local && _local->release() <= 0) {
75+
if (_local && _local->release() == 0) {
7676
delete _local;
7777
}
7878

79-
if (_remote && _remote->release() <= 0) {
79+
if (_remote && _remote->release() == 0) {
8080
delete _remote;
8181
}
8282
}

src/BLEDescriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ BLEDescriptor::BLEDescriptor(const BLEDescriptor& other)
7272

7373
BLEDescriptor::~BLEDescriptor()
7474
{
75-
if (_local && _local->release() <= 0) {
75+
if (_local && _local->release() == 0) {
7676
delete _local;
7777
}
7878

79-
if (_remote && _remote->release() <= 0) {
79+
if (_remote && _remote->release() == 0) {
8080
delete _remote;
8181
}
8282
}

src/BLEService.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ BLEService::BLEService(const BLEService& other)
6565

6666
BLEService::~BLEService()
6767
{
68-
if (_local && _local->release() <= 0) {
68+
if (_local && _local->release() == 0) {
6969
delete _local;
7070
}
7171

72-
if (_remote && _remote->release() <= 0) {
72+
if (_remote && _remote->release() == 0) {
7373
delete _remote;
7474
}
7575
}

src/local/BLELocalCharacteristic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ BLELocalCharacteristic::~BLELocalCharacteristic()
6262
for (unsigned int i = 0; i < descriptorCount(); i++) {
6363
BLELocalDescriptor* d = descriptor(i);
6464

65-
if (d->release() <= 0) {
65+
if (d->release() == 0) {
6666
delete d;
6767
}
6868
}

src/local/BLELocalService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BLELocalService::~BLELocalService()
3333
for (unsigned int i = 0; i < characteristicCount(); i++) {
3434
BLELocalCharacteristic* c = characteristic(i);
3535

36-
if (c->release() <= 0) {
36+
if (c->release() == 0) {
3737
delete c;
3838
}
3939
}

src/remote/BLERemoteCharacteristic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ BLERemoteCharacteristic::~BLERemoteCharacteristic()
4444
for (unsigned int i = 0; i < descriptorCount(); i++) {
4545
BLERemoteDescriptor* d = descriptor(i);
4646

47-
if (d->release() <= 0) {
47+
if (d->release() == 0) {
4848
delete d;
4949
}
5050
}

src/remote/BLERemoteDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void BLERemoteDevice::clearServices()
5050
for (unsigned int i = 0; i < serviceCount(); i++) {
5151
BLERemoteService* s = service(i);
5252

53-
if (s->release() <= 0) {
53+
if (s->release() == 0) {
5454
delete s;
5555
}
5656
}

src/remote/BLERemoteService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BLERemoteService::~BLERemoteService()
3131
for (unsigned int i = 0; i < characteristicCount(); i++) {
3232
BLERemoteCharacteristic* c = characteristic(i);
3333

34-
if (c->release() <= 0) {
34+
if (c->release() == 0) {
3535
delete c;
3636
}
3737
}

src/utility/GATT.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ GATTClass::GATTClass() :
3838

3939
GATTClass::~GATTClass()
4040
{
41-
clearAttributes();
41+
end();
4242
}
4343

4444
void GATTClass::begin()
@@ -70,7 +70,22 @@ void GATTClass::begin()
7070

7171
void GATTClass::end()
7272
{
73-
_attributes.clear();
73+
if (_genericAccessService->release() == 0)
74+
delete(_genericAccessService);
75+
76+
if (_deviceNameCharacteristic->release() == 0)
77+
delete(_deviceNameCharacteristic);
78+
79+
if (_appearanceCharacteristic->release() == 0)
80+
delete(_appearanceCharacteristic);
81+
82+
if (_genericAttributeService->release() == 0)
83+
delete(_genericAttributeService);
84+
85+
if (_servicesChangedCharacteristic->release() == 0)
86+
delete(_servicesChangedCharacteristic);
87+
88+
clearAttributes();
7489
}
7590

7691
void GATTClass::setDeviceName(const char* deviceName)
@@ -164,7 +179,7 @@ void GATTClass::clearAttributes()
164179
for (unsigned int i = 0; i < attributeCount(); i++) {
165180
BLELocalAttribute* a = attribute(i);
166181

167-
if (a->release() <= 0) {
182+
if (a->release() == 0) {
168183
delete a;
169184
}
170185
}

src/utility/HCICordioTransport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ void HCICordioTransportClass::end()
234234
delete bleLoopThread;
235235
bleLoopThread = NULL;
236236
}
237+
238+
#if !defined(ARDUINO_PORTENTA_H7_M4) && !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION)
237239
CordioHCIHook::getDriver().terminate();
240+
#endif
238241

239242
_begun = false;
240243
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy