Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLEEndPoint ref count overflow check #16046

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ble/BLEEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,15 @@ CHIP_ERROR BLEEndPoint::Init(BleLayer * bleLayer, BLE_CONNECTION_OBJECT connObj,
return CHIP_NO_ERROR;
}

void BLEEndPoint::AddRef()
{
VerifyOrDie(mRefCount < UINT32_MAX);
mRefCount++;
}

void BLEEndPoint::Release()
{
VerifyOrDie(mRefCount > 0u);
// Decrement the ref count. When it reaches zero, NULL out the pointer to the chip::System::Layer
// object. This effectively declared the object free and ready for re-allocation.
mRefCount--;
Expand Down
2 changes: 1 addition & 1 deletion src/ble/BLEEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DLL_EXPORT BLEEndPoint

uint32_t mRefCount;

void AddRef() { mRefCount++; }
void AddRef();
void Release();

// Private data members:
Expand Down