Skip to content

Commit

Permalink
BLEEndPoint ref count overflow check (#16046)
Browse files Browse the repository at this point in the history
* BLEEndPoint ref count overflow check

* Assert preconditions for BLEEndPoint ref counting
  • Loading branch information
lzgrablic02 authored and pull[bot] committed May 11, 2022
1 parent 81e053d commit 1530592
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 1530592

Please sign in to comment.