Skip to content

Commit

Permalink
[darwin] ROOT LEAK: <chip::DeviceLayer::Internal::Ble*DelegateImpl (#…
Browse files Browse the repository at this point in the history
…22374)

* [darwin] ROOT LEAK: <chip::DeviceLayer::Internal::Ble*DelegateImpl

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
vivien-apple and bzbarsky-apple authored Sep 3, 2022
1 parent b1e29d4 commit ba8a495
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/platform/Darwin/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,42 @@ CHIP_ERROR BLEManagerImpl::_Init()
BleApplicationDelegateImpl * appDelegate = new BleApplicationDelegateImpl();
BleConnectionDelegateImpl * connDelegate = new BleConnectionDelegateImpl();
BlePlatformDelegateImpl * platformDelegate = new BlePlatformDelegateImpl();

mApplicationDelegate = appDelegate;
mConnectionDelegate = connDelegate;
mPlatformDelegate = platformDelegate;

err = BleLayer::Init(platformDelegate, connDelegate, appDelegate, &DeviceLayer::SystemLayer());

if (CHIP_NO_ERROR != err)
{
_Shutdown();
}

return err;
}

void BLEManagerImpl::_Shutdown()
{
if (mApplicationDelegate)
{
delete mApplicationDelegate;
mApplicationDelegate = nullptr;
}

if (mConnectionDelegate)
{
delete mConnectionDelegate;
mConnectionDelegate = nullptr;
}

if (mPlatformDelegate)
{
delete mPlatformDelegate;
mPlatformDelegate = nullptr;
}
}

bool BLEManagerImpl::_IsAdvertisingEnabled(void)
{
ChipLogDetail(DeviceLayer, "%s", __FUNCTION__);
Expand Down
6 changes: 5 additions & 1 deletion src/platform/Darwin/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer
// ===== Members that implement the BLEManager internal interface.

CHIP_ERROR _Init(void);
void _Shutdown() {}
void _Shutdown();
bool _IsAdvertisingEnabled(void);
CHIP_ERROR _SetAdvertisingEnabled(bool val);
bool _IsAdvertising(void);
Expand All @@ -64,6 +64,10 @@ class BLEManagerImpl final : public BLEManager, private BleLayer
friend BLEManagerImpl & BLEMgrImpl(void);

static BLEManagerImpl sInstance;

BleConnectionDelegate * mConnectionDelegate = nullptr;
BlePlatformDelegate * mPlatformDelegate = nullptr;
BleApplicationDelegate * mApplicationDelegate = nullptr;
};

/**
Expand Down

0 comments on commit ba8a495

Please sign in to comment.